Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007-8 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 | * OTHER DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: Dave Airlie |
| 24 | * Alex Deucher |
| 25 | */ |
| 26 | #include "drmP.h" |
| 27 | #include "drm_edid.h" |
| 28 | #include "drm_crtc_helper.h" |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 29 | #include "drm_fb_helper.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 30 | #include "radeon_drm.h" |
| 31 | #include "radeon.h" |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 32 | #include "atom.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 33 | |
| 34 | extern void |
| 35 | radeon_combios_connected_scratch_regs(struct drm_connector *connector, |
| 36 | struct drm_encoder *encoder, |
| 37 | bool connected); |
| 38 | extern void |
| 39 | radeon_atombios_connected_scratch_regs(struct drm_connector *connector, |
| 40 | struct drm_encoder *encoder, |
| 41 | bool connected); |
| 42 | |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 43 | void radeon_connector_hotplug(struct drm_connector *connector) |
| 44 | { |
| 45 | struct drm_device *dev = connector->dev; |
| 46 | struct radeon_device *rdev = dev->dev_private; |
| 47 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 48 | |
| 49 | if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) |
| 50 | radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); |
| 51 | |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 52 | if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) || |
| 53 | (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) { |
| 54 | if ((radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) || |
| 55 | (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_eDP)) { |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 56 | if (radeon_dp_needs_link_train(radeon_connector)) { |
| 57 | if (connector->encoder) |
| 58 | dp_link_train(connector->encoder, connector); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 65 | static void radeon_property_change_mode(struct drm_encoder *encoder) |
| 66 | { |
| 67 | struct drm_crtc *crtc = encoder->crtc; |
| 68 | |
| 69 | if (crtc && crtc->enabled) { |
| 70 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 71 | crtc->x, crtc->y, crtc->fb); |
| 72 | } |
| 73 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 74 | static void |
| 75 | radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status) |
| 76 | { |
| 77 | struct drm_device *dev = connector->dev; |
| 78 | struct radeon_device *rdev = dev->dev_private; |
| 79 | struct drm_encoder *best_encoder = NULL; |
| 80 | struct drm_encoder *encoder = NULL; |
| 81 | struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; |
| 82 | struct drm_mode_object *obj; |
| 83 | bool connected; |
| 84 | int i; |
| 85 | |
| 86 | best_encoder = connector_funcs->best_encoder(connector); |
| 87 | |
| 88 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 89 | if (connector->encoder_ids[i] == 0) |
| 90 | break; |
| 91 | |
| 92 | obj = drm_mode_object_find(connector->dev, |
| 93 | connector->encoder_ids[i], |
| 94 | DRM_MODE_OBJECT_ENCODER); |
| 95 | if (!obj) |
| 96 | continue; |
| 97 | |
| 98 | encoder = obj_to_encoder(obj); |
| 99 | |
| 100 | if ((encoder == best_encoder) && (status == connector_status_connected)) |
| 101 | connected = true; |
| 102 | else |
| 103 | connected = false; |
| 104 | |
| 105 | if (rdev->is_atom_bios) |
| 106 | radeon_atombios_connected_scratch_regs(connector, encoder, connected); |
| 107 | else |
| 108 | radeon_combios_connected_scratch_regs(connector, encoder, connected); |
| 109 | |
| 110 | } |
| 111 | } |
| 112 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 113 | struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type) |
| 114 | { |
| 115 | struct drm_mode_object *obj; |
| 116 | struct drm_encoder *encoder; |
| 117 | int i; |
| 118 | |
| 119 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 120 | if (connector->encoder_ids[i] == 0) |
| 121 | break; |
| 122 | |
| 123 | obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER); |
| 124 | if (!obj) |
| 125 | continue; |
| 126 | |
| 127 | encoder = obj_to_encoder(obj); |
| 128 | if (encoder->encoder_type == encoder_type) |
| 129 | return encoder; |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 134 | struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector) |
| 135 | { |
| 136 | int enc_id = connector->encoder_ids[0]; |
| 137 | struct drm_mode_object *obj; |
| 138 | struct drm_encoder *encoder; |
| 139 | |
| 140 | /* pick the encoder ids */ |
| 141 | if (enc_id) { |
| 142 | obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER); |
| 143 | if (!obj) |
| 144 | return NULL; |
| 145 | encoder = obj_to_encoder(obj); |
| 146 | return encoder; |
| 147 | } |
| 148 | return NULL; |
| 149 | } |
| 150 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 151 | /* |
| 152 | * radeon_connector_analog_encoder_conflict_solve |
| 153 | * - search for other connectors sharing this encoder |
| 154 | * if priority is true, then set them disconnected if this is connected |
| 155 | * if priority is false, set us disconnected if they are connected |
| 156 | */ |
| 157 | static enum drm_connector_status |
| 158 | radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector, |
| 159 | struct drm_encoder *encoder, |
| 160 | enum drm_connector_status current_status, |
| 161 | bool priority) |
| 162 | { |
| 163 | struct drm_device *dev = connector->dev; |
| 164 | struct drm_connector *conflict; |
| 165 | int i; |
| 166 | |
| 167 | list_for_each_entry(conflict, &dev->mode_config.connector_list, head) { |
| 168 | if (conflict == connector) |
| 169 | continue; |
| 170 | |
| 171 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 172 | if (conflict->encoder_ids[i] == 0) |
| 173 | break; |
| 174 | |
| 175 | /* if the IDs match */ |
| 176 | if (conflict->encoder_ids[i] == encoder->base.id) { |
| 177 | if (conflict->status != connector_status_connected) |
| 178 | continue; |
| 179 | |
| 180 | if (priority == true) { |
| 181 | DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict)); |
| 182 | DRM_INFO("in favor of %s\n", drm_get_connector_name(connector)); |
| 183 | conflict->status = connector_status_disconnected; |
| 184 | radeon_connector_update_scratch_regs(conflict, connector_status_disconnected); |
| 185 | } else { |
| 186 | DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector)); |
| 187 | DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict)); |
| 188 | current_status = connector_status_disconnected; |
| 189 | } |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | return current_status; |
| 195 | |
| 196 | } |
| 197 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 198 | static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder) |
| 199 | { |
| 200 | struct drm_device *dev = encoder->dev; |
| 201 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 202 | struct drm_display_mode *mode = NULL; |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 203 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 204 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 205 | if (native_mode->hdisplay != 0 && |
| 206 | native_mode->vdisplay != 0 && |
| 207 | native_mode->clock != 0) { |
Alex Deucher | fb06ca8 | 2009-10-12 11:25:05 -0400 | [diff] [blame] | 208 | mode = drm_mode_duplicate(dev, native_mode); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 209 | mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; |
| 210 | drm_mode_set_name(mode); |
| 211 | |
| 212 | DRM_DEBUG("Adding native panel mode %s\n", mode->name); |
Alex Deucher | d2efdf6 | 2009-12-22 10:06:49 -0500 | [diff] [blame] | 213 | } else if (native_mode->hdisplay != 0 && |
| 214 | native_mode->vdisplay != 0) { |
| 215 | /* mac laptops without an edid */ |
| 216 | /* Note that this is not necessarily the exact panel mode, |
| 217 | * but an approximation based on the cvt formula. For these |
| 218 | * systems we should ideally read the mode info out of the |
| 219 | * registers or add a mode table, but this works and is much |
| 220 | * simpler. |
| 221 | */ |
| 222 | mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false); |
| 223 | mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; |
| 224 | DRM_DEBUG("Adding cvt approximation of native panel mode %s\n", mode->name); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 225 | } |
| 226 | return mode; |
| 227 | } |
| 228 | |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 229 | static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector) |
| 230 | { |
| 231 | struct drm_device *dev = encoder->dev; |
| 232 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 233 | struct drm_display_mode *mode = NULL; |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 234 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 235 | int i; |
| 236 | struct mode_size { |
| 237 | int w; |
| 238 | int h; |
| 239 | } common_modes[17] = { |
| 240 | { 640, 480}, |
| 241 | { 720, 480}, |
| 242 | { 800, 600}, |
| 243 | { 848, 480}, |
| 244 | {1024, 768}, |
| 245 | {1152, 768}, |
| 246 | {1280, 720}, |
| 247 | {1280, 800}, |
| 248 | {1280, 854}, |
| 249 | {1280, 960}, |
| 250 | {1280, 1024}, |
| 251 | {1440, 900}, |
| 252 | {1400, 1050}, |
| 253 | {1680, 1050}, |
| 254 | {1600, 1200}, |
| 255 | {1920, 1080}, |
| 256 | {1920, 1200} |
| 257 | }; |
| 258 | |
| 259 | for (i = 0; i < 17; i++) { |
Alex Deucher | dfdd646 | 2009-10-13 12:48:44 -0400 | [diff] [blame] | 260 | if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) { |
| 261 | if (common_modes[i].w > 1024 || |
| 262 | common_modes[i].h > 768) |
| 263 | continue; |
| 264 | } |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 265 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 266 | if (common_modes[i].w > native_mode->hdisplay || |
| 267 | common_modes[i].h > native_mode->vdisplay || |
| 268 | (common_modes[i].w == native_mode->hdisplay && |
| 269 | common_modes[i].h == native_mode->vdisplay)) |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 270 | continue; |
| 271 | } |
| 272 | if (common_modes[i].w < 320 || common_modes[i].h < 200) |
| 273 | continue; |
| 274 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 275 | mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false); |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 276 | drm_mode_probed_add(connector, mode); |
| 277 | } |
| 278 | } |
| 279 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 280 | int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property, |
| 281 | uint64_t val) |
| 282 | { |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 283 | struct drm_device *dev = connector->dev; |
| 284 | struct radeon_device *rdev = dev->dev_private; |
| 285 | struct drm_encoder *encoder; |
| 286 | struct radeon_encoder *radeon_encoder; |
| 287 | |
| 288 | if (property == rdev->mode_info.coherent_mode_property) { |
| 289 | struct radeon_encoder_atom_dig *dig; |
| 290 | |
| 291 | /* need to find digital encoder on connector */ |
| 292 | encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); |
| 293 | if (!encoder) |
| 294 | return 0; |
| 295 | |
| 296 | radeon_encoder = to_radeon_encoder(encoder); |
| 297 | |
| 298 | if (!radeon_encoder->enc_priv) |
| 299 | return 0; |
| 300 | |
| 301 | dig = radeon_encoder->enc_priv; |
| 302 | dig->coherent_mode = val ? true : false; |
| 303 | radeon_property_change_mode(&radeon_encoder->base); |
| 304 | } |
| 305 | |
| 306 | if (property == rdev->mode_info.tv_std_property) { |
| 307 | encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC); |
| 308 | if (!encoder) { |
| 309 | encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC); |
| 310 | } |
| 311 | |
| 312 | if (!encoder) |
| 313 | return 0; |
| 314 | |
| 315 | radeon_encoder = to_radeon_encoder(encoder); |
| 316 | if (!radeon_encoder->enc_priv) |
| 317 | return 0; |
Alex Deucher | 643acac | 2010-04-05 23:57:52 -0400 | [diff] [blame] | 318 | if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) { |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 319 | struct radeon_encoder_atom_dac *dac_int; |
| 320 | dac_int = radeon_encoder->enc_priv; |
| 321 | dac_int->tv_std = val; |
| 322 | } else { |
| 323 | struct radeon_encoder_tv_dac *dac_int; |
| 324 | dac_int = radeon_encoder->enc_priv; |
| 325 | dac_int->tv_std = val; |
| 326 | } |
| 327 | radeon_property_change_mode(&radeon_encoder->base); |
| 328 | } |
| 329 | |
| 330 | if (property == rdev->mode_info.load_detect_property) { |
| 331 | struct radeon_connector *radeon_connector = |
| 332 | to_radeon_connector(connector); |
| 333 | |
| 334 | if (val == 0) |
| 335 | radeon_connector->dac_load_detect = false; |
| 336 | else |
| 337 | radeon_connector->dac_load_detect = true; |
| 338 | } |
| 339 | |
| 340 | if (property == rdev->mode_info.tmds_pll_property) { |
| 341 | struct radeon_encoder_int_tmds *tmds = NULL; |
| 342 | bool ret = false; |
| 343 | /* need to find digital encoder on connector */ |
| 344 | encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); |
| 345 | if (!encoder) |
| 346 | return 0; |
| 347 | |
| 348 | radeon_encoder = to_radeon_encoder(encoder); |
| 349 | |
| 350 | tmds = radeon_encoder->enc_priv; |
| 351 | if (!tmds) |
| 352 | return 0; |
| 353 | |
| 354 | if (val == 0) { |
| 355 | if (rdev->is_atom_bios) |
| 356 | ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds); |
| 357 | else |
| 358 | ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds); |
| 359 | } |
| 360 | if (val == 1 || ret == false) { |
| 361 | radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds); |
| 362 | } |
| 363 | radeon_property_change_mode(&radeon_encoder->base); |
| 364 | } |
| 365 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 369 | static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder, |
| 370 | struct drm_connector *connector) |
| 371 | { |
| 372 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 373 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 374 | |
| 375 | /* Try to get native mode details from EDID if necessary */ |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 376 | if (!native_mode->clock) { |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 377 | struct drm_display_mode *t, *mode; |
| 378 | |
| 379 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) { |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 380 | if (mode->hdisplay == native_mode->hdisplay && |
| 381 | mode->vdisplay == native_mode->vdisplay) { |
| 382 | *native_mode = *mode; |
| 383 | drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V); |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 384 | DRM_INFO("Determined LVDS native mode details from EDID\n"); |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | } |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 389 | if (!native_mode->clock) { |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 390 | DRM_INFO("No LVDS native mode details, disabling RMX\n"); |
| 391 | radeon_encoder->rmx_type = RMX_OFF; |
| 392 | } |
| 393 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 394 | |
| 395 | static int radeon_lvds_get_modes(struct drm_connector *connector) |
| 396 | { |
| 397 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 398 | struct drm_encoder *encoder; |
| 399 | int ret = 0; |
| 400 | struct drm_display_mode *mode; |
| 401 | |
| 402 | if (radeon_connector->ddc_bus) { |
| 403 | ret = radeon_ddc_get_modes(radeon_connector); |
| 404 | if (ret > 0) { |
Alex Deucher | 7747b71 | 2009-09-11 11:15:43 -0400 | [diff] [blame] | 405 | encoder = radeon_best_single_encoder(connector); |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 406 | if (encoder) { |
| 407 | radeon_fixup_lvds_native_mode(encoder, connector); |
Alex Deucher | 7747b71 | 2009-09-11 11:15:43 -0400 | [diff] [blame] | 408 | /* add scaled modes */ |
| 409 | radeon_add_common_modes(encoder, connector); |
Michel Dänzer | 8dfaa8a | 2009-09-15 17:09:27 +0200 | [diff] [blame] | 410 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 411 | return ret; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | encoder = radeon_best_single_encoder(connector); |
| 416 | if (!encoder) |
| 417 | return 0; |
| 418 | |
| 419 | /* we have no EDID modes */ |
| 420 | mode = radeon_fp_native_mode(encoder); |
| 421 | if (mode) { |
| 422 | ret = 1; |
| 423 | drm_mode_probed_add(connector, mode); |
Alex Deucher | 7747b71 | 2009-09-11 11:15:43 -0400 | [diff] [blame] | 424 | /* add scaled modes */ |
| 425 | radeon_add_common_modes(encoder, connector); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 426 | } |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 427 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | static int radeon_lvds_mode_valid(struct drm_connector *connector, |
| 432 | struct drm_display_mode *mode) |
| 433 | { |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 434 | struct drm_encoder *encoder = radeon_best_single_encoder(connector); |
| 435 | |
| 436 | if ((mode->hdisplay < 320) || (mode->vdisplay < 240)) |
| 437 | return MODE_PANEL; |
| 438 | |
| 439 | if (encoder) { |
| 440 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 441 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
| 442 | |
| 443 | /* AVIVO hardware supports downscaling modes larger than the panel |
| 444 | * to the panel size, but I'm not sure this is desirable. |
| 445 | */ |
| 446 | if ((mode->hdisplay > native_mode->hdisplay) || |
| 447 | (mode->vdisplay > native_mode->vdisplay)) |
| 448 | return MODE_PANEL; |
| 449 | |
| 450 | /* if scaling is disabled, block non-native modes */ |
| 451 | if (radeon_encoder->rmx_type == RMX_OFF) { |
| 452 | if ((mode->hdisplay != native_mode->hdisplay) || |
| 453 | (mode->vdisplay != native_mode->vdisplay)) |
| 454 | return MODE_PANEL; |
| 455 | } |
| 456 | } |
| 457 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 458 | return MODE_OK; |
| 459 | } |
| 460 | |
| 461 | static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector) |
| 462 | { |
Alex Deucher | 0549a061 | 2009-10-09 18:41:19 -0400 | [diff] [blame] | 463 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Alex Deucher | 2ffb842 | 2009-10-08 13:02:19 -0400 | [diff] [blame] | 464 | struct drm_encoder *encoder = radeon_best_single_encoder(connector); |
Alex Deucher | 0549a061 | 2009-10-09 18:41:19 -0400 | [diff] [blame] | 465 | enum drm_connector_status ret = connector_status_disconnected; |
Alex Deucher | 2ffb842 | 2009-10-08 13:02:19 -0400 | [diff] [blame] | 466 | |
| 467 | if (encoder) { |
| 468 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 469 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
Alex Deucher | 2ffb842 | 2009-10-08 13:02:19 -0400 | [diff] [blame] | 470 | |
| 471 | /* check if panel is valid */ |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 472 | if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) |
Alex Deucher | 2ffb842 | 2009-10-08 13:02:19 -0400 | [diff] [blame] | 473 | ret = connector_status_connected; |
| 474 | |
| 475 | } |
Alex Deucher | 0549a061 | 2009-10-09 18:41:19 -0400 | [diff] [blame] | 476 | |
| 477 | /* check for edid as well */ |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 478 | if (radeon_connector->edid) |
| 479 | ret = connector_status_connected; |
| 480 | else { |
| 481 | if (radeon_connector->ddc_bus) { |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 482 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, |
| 483 | &radeon_connector->ddc_bus->adapter); |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 484 | if (radeon_connector->edid) |
| 485 | ret = connector_status_connected; |
| 486 | } |
Alex Deucher | 0549a061 | 2009-10-09 18:41:19 -0400 | [diff] [blame] | 487 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 488 | /* check acpi lid status ??? */ |
Alex Deucher | 2ffb842 | 2009-10-08 13:02:19 -0400 | [diff] [blame] | 489 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 490 | radeon_connector_update_scratch_regs(connector, ret); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | static void radeon_connector_destroy(struct drm_connector *connector) |
| 495 | { |
| 496 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 497 | |
| 498 | if (radeon_connector->ddc_bus) |
| 499 | radeon_i2c_destroy(radeon_connector->ddc_bus); |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 500 | if (radeon_connector->edid) |
| 501 | kfree(radeon_connector->edid); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 502 | kfree(radeon_connector->con_priv); |
| 503 | drm_sysfs_connector_remove(connector); |
| 504 | drm_connector_cleanup(connector); |
| 505 | kfree(connector); |
| 506 | } |
| 507 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 508 | static int radeon_lvds_set_property(struct drm_connector *connector, |
| 509 | struct drm_property *property, |
| 510 | uint64_t value) |
| 511 | { |
| 512 | struct drm_device *dev = connector->dev; |
| 513 | struct radeon_encoder *radeon_encoder; |
| 514 | enum radeon_rmx_type rmx_type; |
| 515 | |
| 516 | DRM_DEBUG("\n"); |
| 517 | if (property != dev->mode_config.scaling_mode_property) |
| 518 | return 0; |
| 519 | |
| 520 | if (connector->encoder) |
| 521 | radeon_encoder = to_radeon_encoder(connector->encoder); |
| 522 | else { |
| 523 | struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; |
| 524 | radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector)); |
| 525 | } |
| 526 | |
| 527 | switch (value) { |
| 528 | case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break; |
| 529 | case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break; |
| 530 | case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break; |
| 531 | default: |
| 532 | case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break; |
| 533 | } |
| 534 | if (radeon_encoder->rmx_type == rmx_type) |
| 535 | return 0; |
| 536 | |
| 537 | radeon_encoder->rmx_type = rmx_type; |
| 538 | |
| 539 | radeon_property_change_mode(&radeon_encoder->base); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 544 | struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = { |
| 545 | .get_modes = radeon_lvds_get_modes, |
| 546 | .mode_valid = radeon_lvds_mode_valid, |
| 547 | .best_encoder = radeon_best_single_encoder, |
| 548 | }; |
| 549 | |
| 550 | struct drm_connector_funcs radeon_lvds_connector_funcs = { |
| 551 | .dpms = drm_helper_connector_dpms, |
| 552 | .detect = radeon_lvds_detect, |
| 553 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 554 | .destroy = radeon_connector_destroy, |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 555 | .set_property = radeon_lvds_set_property, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | static int radeon_vga_get_modes(struct drm_connector *connector) |
| 559 | { |
| 560 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 561 | int ret; |
| 562 | |
| 563 | ret = radeon_ddc_get_modes(radeon_connector); |
| 564 | |
| 565 | return ret; |
| 566 | } |
| 567 | |
| 568 | static int radeon_vga_mode_valid(struct drm_connector *connector, |
| 569 | struct drm_display_mode *mode) |
| 570 | { |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 571 | /* XXX check mode bandwidth */ |
| 572 | /* XXX verify against max DAC output frequency */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 573 | return MODE_OK; |
| 574 | } |
| 575 | |
| 576 | static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector) |
| 577 | { |
| 578 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 579 | struct drm_encoder *encoder; |
| 580 | struct drm_encoder_helper_funcs *encoder_funcs; |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 581 | bool dret = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 582 | enum drm_connector_status ret = connector_status_disconnected; |
| 583 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 584 | encoder = radeon_best_single_encoder(connector); |
| 585 | if (!encoder) |
| 586 | ret = connector_status_disconnected; |
| 587 | |
Dave Airlie | eb6b6d7 | 2010-02-25 13:44:04 +1000 | [diff] [blame] | 588 | if (radeon_connector->ddc_bus) |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 589 | dret = radeon_ddc_probe(radeon_connector); |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 590 | if (dret) { |
| 591 | if (radeon_connector->edid) { |
| 592 | kfree(radeon_connector->edid); |
| 593 | radeon_connector->edid = NULL; |
| 594 | } |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 595 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 596 | |
| 597 | if (!radeon_connector->edid) { |
Jerome Glisse | f82f5f3 | 2009-11-12 14:13:53 +0100 | [diff] [blame] | 598 | DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", |
| 599 | drm_get_connector_name(connector)); |
| 600 | ret = connector_status_connected; |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 601 | } else { |
| 602 | radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL); |
| 603 | |
| 604 | /* some oems have boards with separate digital and analog connectors |
| 605 | * with a shared ddc line (often vga + hdmi) |
| 606 | */ |
| 607 | if (radeon_connector->use_digital && radeon_connector->shared_ddc) { |
| 608 | kfree(radeon_connector->edid); |
| 609 | radeon_connector->edid = NULL; |
| 610 | ret = connector_status_disconnected; |
| 611 | } else |
| 612 | ret = connector_status_connected; |
| 613 | } |
| 614 | } else { |
Darren Jenkins | d8a7f79 | 2009-12-30 12:22:55 +1100 | [diff] [blame] | 615 | if (radeon_connector->dac_load_detect && encoder) { |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 616 | encoder_funcs = encoder->helper_private; |
| 617 | ret = encoder_funcs->detect(encoder, connector); |
| 618 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 621 | if (ret == connector_status_connected) |
| 622 | ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 623 | radeon_connector_update_scratch_regs(connector, ret); |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = { |
| 628 | .get_modes = radeon_vga_get_modes, |
| 629 | .mode_valid = radeon_vga_mode_valid, |
| 630 | .best_encoder = radeon_best_single_encoder, |
| 631 | }; |
| 632 | |
| 633 | struct drm_connector_funcs radeon_vga_connector_funcs = { |
| 634 | .dpms = drm_helper_connector_dpms, |
| 635 | .detect = radeon_vga_detect, |
| 636 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 637 | .destroy = radeon_connector_destroy, |
| 638 | .set_property = radeon_connector_set_property, |
| 639 | }; |
| 640 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 641 | static int radeon_tv_get_modes(struct drm_connector *connector) |
| 642 | { |
| 643 | struct drm_device *dev = connector->dev; |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 644 | struct radeon_device *rdev = dev->dev_private; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 645 | struct drm_display_mode *tv_mode; |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 646 | struct drm_encoder *encoder; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 647 | |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 648 | encoder = radeon_best_single_encoder(connector); |
| 649 | if (!encoder) |
| 650 | return 0; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 651 | |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 652 | /* avivo chips can scale any mode */ |
| 653 | if (rdev->family >= CHIP_RS600) |
| 654 | /* add scaled modes */ |
| 655 | radeon_add_common_modes(encoder, connector); |
| 656 | else { |
| 657 | /* only 800x600 is supported right now on pre-avivo chips */ |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 658 | tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false); |
Alex Deucher | 923f684 | 2009-09-10 17:53:39 -0400 | [diff] [blame] | 659 | tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; |
| 660 | drm_mode_probed_add(connector, tv_mode); |
| 661 | } |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 662 | return 1; |
| 663 | } |
| 664 | |
| 665 | static int radeon_tv_mode_valid(struct drm_connector *connector, |
| 666 | struct drm_display_mode *mode) |
| 667 | { |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 668 | if ((mode->hdisplay > 1024) || (mode->vdisplay > 768)) |
| 669 | return MODE_CLOCK_RANGE; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 670 | return MODE_OK; |
| 671 | } |
| 672 | |
| 673 | static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector) |
| 674 | { |
| 675 | struct drm_encoder *encoder; |
| 676 | struct drm_encoder_helper_funcs *encoder_funcs; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 677 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 678 | enum drm_connector_status ret = connector_status_disconnected; |
| 679 | |
| 680 | if (!radeon_connector->dac_load_detect) |
| 681 | return ret; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 682 | |
| 683 | encoder = radeon_best_single_encoder(connector); |
| 684 | if (!encoder) |
| 685 | ret = connector_status_disconnected; |
| 686 | else { |
| 687 | encoder_funcs = encoder->helper_private; |
| 688 | ret = encoder_funcs->detect(encoder, connector); |
| 689 | } |
| 690 | if (ret == connector_status_connected) |
| 691 | ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false); |
| 692 | radeon_connector_update_scratch_regs(connector, ret); |
| 693 | return ret; |
| 694 | } |
| 695 | |
| 696 | struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = { |
| 697 | .get_modes = radeon_tv_get_modes, |
| 698 | .mode_valid = radeon_tv_mode_valid, |
| 699 | .best_encoder = radeon_best_single_encoder, |
| 700 | }; |
| 701 | |
| 702 | struct drm_connector_funcs radeon_tv_connector_funcs = { |
| 703 | .dpms = drm_helper_connector_dpms, |
| 704 | .detect = radeon_tv_detect, |
| 705 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 706 | .destroy = radeon_connector_destroy, |
| 707 | .set_property = radeon_connector_set_property, |
| 708 | }; |
| 709 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 710 | static int radeon_dvi_get_modes(struct drm_connector *connector) |
| 711 | { |
| 712 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 713 | int ret; |
| 714 | |
| 715 | ret = radeon_ddc_get_modes(radeon_connector); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 716 | return ret; |
| 717 | } |
| 718 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 719 | /* |
| 720 | * DVI is complicated |
| 721 | * Do a DDC probe, if DDC probe passes, get the full EDID so |
| 722 | * we can do analog/digital monitor detection at this point. |
| 723 | * If the monitor is an analog monitor or we got no DDC, |
| 724 | * we need to find the DAC encoder object for this connector. |
| 725 | * If we got no DDC, we do load detection on the DAC encoder object. |
| 726 | * If we got analog DDC or load detection passes on the DAC encoder |
| 727 | * we have to check if this analog encoder is shared with anyone else (TV) |
| 728 | * if its shared we have to set the other connector to disconnected. |
| 729 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 730 | static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector) |
| 731 | { |
| 732 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 733 | struct drm_encoder *encoder = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 734 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 735 | struct drm_mode_object *obj; |
| 736 | int i; |
| 737 | enum drm_connector_status ret = connector_status_disconnected; |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 738 | bool dret = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 739 | |
Dave Airlie | eb6b6d7 | 2010-02-25 13:44:04 +1000 | [diff] [blame] | 740 | if (radeon_connector->ddc_bus) |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 741 | dret = radeon_ddc_probe(radeon_connector); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 742 | if (dret) { |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 743 | if (radeon_connector->edid) { |
| 744 | kfree(radeon_connector->edid); |
| 745 | radeon_connector->edid = NULL; |
| 746 | } |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 747 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 748 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 749 | if (!radeon_connector->edid) { |
Jerome Glisse | f82f5f3 | 2009-11-12 14:13:53 +0100 | [diff] [blame] | 750 | DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", |
| 751 | drm_get_connector_name(connector)); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 752 | } else { |
| 753 | radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 754 | |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 755 | /* some oems have boards with separate digital and analog connectors |
| 756 | * with a shared ddc line (often vga + hdmi) |
| 757 | */ |
| 758 | if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) { |
| 759 | kfree(radeon_connector->edid); |
| 760 | radeon_connector->edid = NULL; |
| 761 | ret = connector_status_disconnected; |
| 762 | } else |
| 763 | ret = connector_status_connected; |
Alex Deucher | 71407c4 | 2009-11-17 15:44:01 -0500 | [diff] [blame] | 764 | |
| 765 | /* multiple connectors on the same encoder with the same ddc line |
| 766 | * This tends to be HDMI and DVI on the same encoder with the |
| 767 | * same ddc line. If the edid says HDMI, consider the HDMI port |
| 768 | * connected and the DVI port disconnected. If the edid doesn't |
| 769 | * say HDMI, vice versa. |
| 770 | */ |
Alex Deucher | d3932d6 | 2010-02-19 02:13:56 -0500 | [diff] [blame] | 771 | if (radeon_connector->shared_ddc && (ret == connector_status_connected)) { |
Alex Deucher | 71407c4 | 2009-11-17 15:44:01 -0500 | [diff] [blame] | 772 | struct drm_device *dev = connector->dev; |
| 773 | struct drm_connector *list_connector; |
| 774 | struct radeon_connector *list_radeon_connector; |
| 775 | list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) { |
| 776 | if (connector == list_connector) |
| 777 | continue; |
| 778 | list_radeon_connector = to_radeon_connector(list_connector); |
| 779 | if (radeon_connector->devices == list_radeon_connector->devices) { |
| 780 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) { |
| 781 | if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) { |
| 782 | kfree(radeon_connector->edid); |
| 783 | radeon_connector->edid = NULL; |
| 784 | ret = connector_status_disconnected; |
| 785 | } |
| 786 | } else { |
| 787 | if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) || |
| 788 | (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) { |
| 789 | kfree(radeon_connector->edid); |
| 790 | radeon_connector->edid = NULL; |
| 791 | ret = connector_status_disconnected; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 800 | if ((ret == connector_status_connected) && (radeon_connector->use_digital == true)) |
| 801 | goto out; |
| 802 | |
| 803 | /* find analog encoder */ |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 804 | if (radeon_connector->dac_load_detect) { |
| 805 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 806 | if (connector->encoder_ids[i] == 0) |
| 807 | break; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 808 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 809 | obj = drm_mode_object_find(connector->dev, |
| 810 | connector->encoder_ids[i], |
| 811 | DRM_MODE_OBJECT_ENCODER); |
| 812 | if (!obj) |
| 813 | continue; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 814 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 815 | encoder = obj_to_encoder(obj); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 816 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 817 | encoder_funcs = encoder->helper_private; |
| 818 | if (encoder_funcs->detect) { |
| 819 | if (ret != connector_status_connected) { |
| 820 | ret = encoder_funcs->detect(encoder, connector); |
| 821 | if (ret == connector_status_connected) { |
| 822 | radeon_connector->use_digital = false; |
| 823 | } |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 824 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 825 | break; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 826 | } |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
| 830 | if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) && |
| 831 | encoder) { |
| 832 | ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true); |
| 833 | } |
| 834 | |
| 835 | out: |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 836 | /* updated in get modes as well since we need to know if it's analog or digital */ |
| 837 | radeon_connector_update_scratch_regs(connector, ret); |
| 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | /* okay need to be smart in here about which encoder to pick */ |
| 842 | struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector) |
| 843 | { |
| 844 | int enc_id = connector->encoder_ids[0]; |
| 845 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 846 | struct drm_mode_object *obj; |
| 847 | struct drm_encoder *encoder; |
| 848 | int i; |
| 849 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 850 | if (connector->encoder_ids[i] == 0) |
| 851 | break; |
| 852 | |
| 853 | obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER); |
| 854 | if (!obj) |
| 855 | continue; |
| 856 | |
| 857 | encoder = obj_to_encoder(obj); |
| 858 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 859 | if (radeon_connector->use_digital == true) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 860 | if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS) |
| 861 | return encoder; |
| 862 | } else { |
| 863 | if (encoder->encoder_type == DRM_MODE_ENCODER_DAC || |
| 864 | encoder->encoder_type == DRM_MODE_ENCODER_TVDAC) |
| 865 | return encoder; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /* see if we have a default encoder TODO */ |
| 870 | |
| 871 | /* then check use digitial */ |
| 872 | /* pick the first one */ |
| 873 | if (enc_id) { |
| 874 | obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER); |
| 875 | if (!obj) |
| 876 | return NULL; |
| 877 | encoder = obj_to_encoder(obj); |
| 878 | return encoder; |
| 879 | } |
| 880 | return NULL; |
| 881 | } |
| 882 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 883 | static void radeon_dvi_force(struct drm_connector *connector) |
| 884 | { |
| 885 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 886 | if (connector->force == DRM_FORCE_ON) |
| 887 | radeon_connector->use_digital = false; |
| 888 | if (connector->force == DRM_FORCE_ON_DIGITAL) |
| 889 | radeon_connector->use_digital = true; |
| 890 | } |
| 891 | |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 892 | static int radeon_dvi_mode_valid(struct drm_connector *connector, |
| 893 | struct drm_display_mode *mode) |
| 894 | { |
Alex Deucher | 1b24203 | 2010-01-11 15:02:31 -0500 | [diff] [blame] | 895 | struct drm_device *dev = connector->dev; |
| 896 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 897 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 898 | |
| 899 | /* XXX check mode bandwidth */ |
| 900 | |
Alex Deucher | 1b24203 | 2010-01-11 15:02:31 -0500 | [diff] [blame] | 901 | /* clocks over 135 MHz have heat issues with DVI on RV100 */ |
| 902 | if (radeon_connector->use_digital && |
| 903 | (rdev->family == CHIP_RV100) && |
| 904 | (mode->clock > 135000)) |
| 905 | return MODE_CLOCK_HIGH; |
| 906 | |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 907 | if (radeon_connector->use_digital && (mode->clock > 165000)) { |
| 908 | if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) || |
| 909 | (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) || |
| 910 | (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B)) |
| 911 | return MODE_OK; |
| 912 | else |
| 913 | return MODE_CLOCK_HIGH; |
| 914 | } |
| 915 | return MODE_OK; |
| 916 | } |
| 917 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 918 | struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = { |
| 919 | .get_modes = radeon_dvi_get_modes, |
Alex Deucher | a3fa632 | 2009-11-05 11:57:07 -0500 | [diff] [blame] | 920 | .mode_valid = radeon_dvi_mode_valid, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 921 | .best_encoder = radeon_dvi_encoder, |
| 922 | }; |
| 923 | |
| 924 | struct drm_connector_funcs radeon_dvi_connector_funcs = { |
| 925 | .dpms = drm_helper_connector_dpms, |
| 926 | .detect = radeon_dvi_detect, |
| 927 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 928 | .set_property = radeon_connector_set_property, |
| 929 | .destroy = radeon_connector_destroy, |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 930 | .force = radeon_dvi_force, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 931 | }; |
| 932 | |
Alex Deucher | ffd09c6 | 2009-11-24 16:13:23 -0500 | [diff] [blame] | 933 | static void radeon_dp_connector_destroy(struct drm_connector *connector) |
| 934 | { |
| 935 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 936 | struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; |
| 937 | |
| 938 | if (radeon_connector->ddc_bus) |
| 939 | radeon_i2c_destroy(radeon_connector->ddc_bus); |
| 940 | if (radeon_connector->edid) |
| 941 | kfree(radeon_connector->edid); |
| 942 | if (radeon_dig_connector->dp_i2c_bus) |
Alex Deucher | ac1aade | 2010-03-14 12:22:44 -0400 | [diff] [blame] | 943 | radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus); |
Alex Deucher | ffd09c6 | 2009-11-24 16:13:23 -0500 | [diff] [blame] | 944 | kfree(radeon_connector->con_priv); |
| 945 | drm_sysfs_connector_remove(connector); |
| 946 | drm_connector_cleanup(connector); |
| 947 | kfree(connector); |
| 948 | } |
| 949 | |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 950 | static int radeon_dp_get_modes(struct drm_connector *connector) |
| 951 | { |
| 952 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 953 | int ret; |
| 954 | |
| 955 | ret = radeon_ddc_get_modes(radeon_connector); |
| 956 | return ret; |
| 957 | } |
| 958 | |
| 959 | static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector) |
| 960 | { |
| 961 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 962 | enum drm_connector_status ret = connector_status_disconnected; |
Alex Deucher | 4143e91 | 2009-11-23 18:02:35 -0500 | [diff] [blame] | 963 | struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; |
| 964 | u8 sink_type; |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 965 | |
| 966 | if (radeon_connector->edid) { |
| 967 | kfree(radeon_connector->edid); |
| 968 | radeon_connector->edid = NULL; |
| 969 | } |
| 970 | |
| 971 | sink_type = radeon_dp_getsinktype(radeon_connector); |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 972 | if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || |
| 973 | (sink_type == CONNECTOR_OBJECT_ID_eDP)) { |
Alex Deucher | 9fa05c9 | 2009-11-27 13:01:46 -0500 | [diff] [blame] | 974 | if (radeon_dp_getdpcd(radeon_connector)) { |
| 975 | radeon_dig_connector->dp_sink_type = sink_type; |
| 976 | ret = connector_status_connected; |
| 977 | } |
Alex Deucher | 4143e91 | 2009-11-23 18:02:35 -0500 | [diff] [blame] | 978 | } else { |
Alex Deucher | 4143e91 | 2009-11-23 18:02:35 -0500 | [diff] [blame] | 979 | if (radeon_ddc_probe(radeon_connector)) { |
| 980 | radeon_dig_connector->dp_sink_type = sink_type; |
| 981 | ret = connector_status_connected; |
| 982 | } |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 983 | } |
Alex Deucher | 4143e91 | 2009-11-23 18:02:35 -0500 | [diff] [blame] | 984 | |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 985 | return ret; |
| 986 | } |
| 987 | |
Alex Deucher | 5801ead | 2009-11-24 13:32:59 -0500 | [diff] [blame] | 988 | static int radeon_dp_mode_valid(struct drm_connector *connector, |
| 989 | struct drm_display_mode *mode) |
| 990 | { |
| 991 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 992 | struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; |
| 993 | |
| 994 | /* XXX check mode bandwidth */ |
| 995 | |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 996 | if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || |
| 997 | (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) |
Alex Deucher | 5801ead | 2009-11-24 13:32:59 -0500 | [diff] [blame] | 998 | return radeon_dp_mode_valid_helper(radeon_connector, mode); |
| 999 | else |
| 1000 | return MODE_OK; |
| 1001 | } |
| 1002 | |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 1003 | struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = { |
| 1004 | .get_modes = radeon_dp_get_modes, |
Alex Deucher | 5801ead | 2009-11-24 13:32:59 -0500 | [diff] [blame] | 1005 | .mode_valid = radeon_dp_mode_valid, |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 1006 | .best_encoder = radeon_dvi_encoder, |
| 1007 | }; |
| 1008 | |
| 1009 | struct drm_connector_funcs radeon_dp_connector_funcs = { |
| 1010 | .dpms = drm_helper_connector_dpms, |
| 1011 | .detect = radeon_dp_detect, |
| 1012 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 1013 | .set_property = radeon_connector_set_property, |
Alex Deucher | ffd09c6 | 2009-11-24 16:13:23 -0500 | [diff] [blame] | 1014 | .destroy = radeon_dp_connector_destroy, |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 1015 | .force = radeon_dvi_force, |
| 1016 | }; |
| 1017 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1018 | void |
| 1019 | radeon_add_atom_connector(struct drm_device *dev, |
| 1020 | uint32_t connector_id, |
| 1021 | uint32_t supported_device, |
| 1022 | int connector_type, |
| 1023 | struct radeon_i2c_bus_rec *i2c_bus, |
| 1024 | bool linkb, |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1025 | uint32_t igp_lane_info, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1026 | uint16_t connector_object_id, |
| 1027 | struct radeon_hpd *hpd) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1028 | { |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1029 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1030 | struct drm_connector *connector; |
| 1031 | struct radeon_connector *radeon_connector; |
| 1032 | struct radeon_connector_atom_dig *radeon_dig_connector; |
| 1033 | uint32_t subpixel_order = SubPixelNone; |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 1034 | bool shared_ddc = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1035 | |
| 1036 | /* fixme - tv/cv/din */ |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1037 | if (connector_type == DRM_MODE_CONNECTOR_Unknown) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1038 | return; |
| 1039 | |
| 1040 | /* see if we already added it */ |
| 1041 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 1042 | radeon_connector = to_radeon_connector(connector); |
| 1043 | if (radeon_connector->connector_id == connector_id) { |
| 1044 | radeon_connector->devices |= supported_device; |
| 1045 | return; |
| 1046 | } |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 1047 | if (radeon_connector->ddc_bus && i2c_bus->valid) { |
Alex Deucher | d3932d6 | 2010-02-19 02:13:56 -0500 | [diff] [blame] | 1048 | if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) { |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 1049 | radeon_connector->shared_ddc = true; |
| 1050 | shared_ddc = true; |
| 1051 | } |
| 1052 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL); |
| 1056 | if (!radeon_connector) |
| 1057 | return; |
| 1058 | |
| 1059 | connector = &radeon_connector->base; |
| 1060 | |
| 1061 | radeon_connector->connector_id = connector_id; |
| 1062 | radeon_connector->devices = supported_device; |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 1063 | radeon_connector->shared_ddc = shared_ddc; |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1064 | radeon_connector->connector_object_id = connector_object_id; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1065 | radeon_connector->hpd = *hpd; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1066 | switch (connector_type) { |
| 1067 | case DRM_MODE_CONNECTOR_VGA: |
| 1068 | drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1069 | drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1070 | if (i2c_bus->valid) { |
| 1071 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); |
| 1072 | if (!radeon_connector->ddc_bus) |
| 1073 | goto failed; |
| 1074 | } |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1075 | radeon_connector->dac_load_detect = true; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1076 | drm_connector_attach_property(&radeon_connector->base, |
| 1077 | rdev->mode_info.load_detect_property, |
| 1078 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1079 | break; |
| 1080 | case DRM_MODE_CONNECTOR_DVIA: |
| 1081 | drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1082 | drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1083 | if (i2c_bus->valid) { |
| 1084 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); |
| 1085 | if (!radeon_connector->ddc_bus) |
| 1086 | goto failed; |
| 1087 | } |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1088 | radeon_connector->dac_load_detect = true; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1089 | drm_connector_attach_property(&radeon_connector->base, |
| 1090 | rdev->mode_info.load_detect_property, |
| 1091 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1092 | break; |
| 1093 | case DRM_MODE_CONNECTOR_DVII: |
| 1094 | case DRM_MODE_CONNECTOR_DVID: |
| 1095 | radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); |
| 1096 | if (!radeon_dig_connector) |
| 1097 | goto failed; |
| 1098 | radeon_dig_connector->linkb = linkb; |
| 1099 | radeon_dig_connector->igp_lane_info = igp_lane_info; |
| 1100 | radeon_connector->con_priv = radeon_dig_connector; |
| 1101 | drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1102 | drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1103 | if (i2c_bus->valid) { |
| 1104 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); |
| 1105 | if (!radeon_connector->ddc_bus) |
| 1106 | goto failed; |
| 1107 | } |
| 1108 | subpixel_order = SubPixelHorizontalRGB; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1109 | drm_connector_attach_property(&radeon_connector->base, |
| 1110 | rdev->mode_info.coherent_mode_property, |
| 1111 | 1); |
Alex Deucher | 390d0bb | 2009-12-08 12:48:20 -0500 | [diff] [blame] | 1112 | if (connector_type == DRM_MODE_CONNECTOR_DVII) { |
| 1113 | radeon_connector->dac_load_detect = true; |
| 1114 | drm_connector_attach_property(&radeon_connector->base, |
| 1115 | rdev->mode_info.load_detect_property, |
| 1116 | 1); |
| 1117 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1118 | break; |
| 1119 | case DRM_MODE_CONNECTOR_HDMIA: |
| 1120 | case DRM_MODE_CONNECTOR_HDMIB: |
| 1121 | radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); |
| 1122 | if (!radeon_dig_connector) |
| 1123 | goto failed; |
| 1124 | radeon_dig_connector->linkb = linkb; |
| 1125 | radeon_dig_connector->igp_lane_info = igp_lane_info; |
| 1126 | radeon_connector->con_priv = radeon_dig_connector; |
| 1127 | drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1128 | drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1129 | if (i2c_bus->valid) { |
| 1130 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI"); |
| 1131 | if (!radeon_connector->ddc_bus) |
| 1132 | goto failed; |
| 1133 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1134 | drm_connector_attach_property(&radeon_connector->base, |
| 1135 | rdev->mode_info.coherent_mode_property, |
| 1136 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1137 | subpixel_order = SubPixelHorizontalRGB; |
| 1138 | break; |
| 1139 | case DRM_MODE_CONNECTOR_DisplayPort: |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 1140 | case DRM_MODE_CONNECTOR_eDP: |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1141 | radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); |
| 1142 | if (!radeon_dig_connector) |
| 1143 | goto failed; |
| 1144 | radeon_dig_connector->linkb = linkb; |
| 1145 | radeon_dig_connector->igp_lane_info = igp_lane_info; |
| 1146 | radeon_connector->con_priv = radeon_dig_connector; |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 1147 | drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1148 | drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1149 | if (i2c_bus->valid) { |
Alex Deucher | 390d0bb | 2009-12-08 12:48:20 -0500 | [diff] [blame] | 1150 | /* add DP i2c bus */ |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 1151 | if (connector_type == DRM_MODE_CONNECTOR_eDP) |
| 1152 | radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch"); |
| 1153 | else |
| 1154 | radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch"); |
Alex Deucher | 390d0bb | 2009-12-08 12:48:20 -0500 | [diff] [blame] | 1155 | if (!radeon_dig_connector->dp_i2c_bus) |
| 1156 | goto failed; |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 1157 | if (connector_type == DRM_MODE_CONNECTOR_eDP) |
| 1158 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP"); |
| 1159 | else |
| 1160 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1161 | if (!radeon_connector->ddc_bus) |
| 1162 | goto failed; |
| 1163 | } |
| 1164 | subpixel_order = SubPixelHorizontalRGB; |
Alex Deucher | 390d0bb | 2009-12-08 12:48:20 -0500 | [diff] [blame] | 1165 | drm_connector_attach_property(&radeon_connector->base, |
| 1166 | rdev->mode_info.coherent_mode_property, |
| 1167 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1168 | break; |
| 1169 | case DRM_MODE_CONNECTOR_SVIDEO: |
| 1170 | case DRM_MODE_CONNECTOR_Composite: |
| 1171 | case DRM_MODE_CONNECTOR_9PinDIN: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1172 | if (radeon_tv == 1) { |
| 1173 | drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1174 | drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs); |
Dave Airlie | 74bf2ad | 2009-09-28 15:31:10 +1000 | [diff] [blame] | 1175 | radeon_connector->dac_load_detect = true; |
| 1176 | drm_connector_attach_property(&radeon_connector->base, |
| 1177 | rdev->mode_info.load_detect_property, |
| 1178 | 1); |
Alex Deucher | ed16014 | 2009-12-01 14:12:14 -0500 | [diff] [blame] | 1179 | drm_connector_attach_property(&radeon_connector->base, |
| 1180 | rdev->mode_info.tv_std_property, |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1181 | radeon_atombios_get_tv_info(rdev)); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1182 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1183 | break; |
| 1184 | case DRM_MODE_CONNECTOR_LVDS: |
| 1185 | radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); |
| 1186 | if (!radeon_dig_connector) |
| 1187 | goto failed; |
| 1188 | radeon_dig_connector->linkb = linkb; |
| 1189 | radeon_dig_connector->igp_lane_info = igp_lane_info; |
| 1190 | radeon_connector->con_priv = radeon_dig_connector; |
| 1191 | drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1192 | drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1193 | if (i2c_bus->valid) { |
| 1194 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); |
| 1195 | if (!radeon_connector->ddc_bus) |
| 1196 | goto failed; |
| 1197 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1198 | drm_connector_attach_property(&radeon_connector->base, |
| 1199 | dev->mode_config.scaling_mode_property, |
| 1200 | DRM_MODE_SCALE_FULLSCREEN); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1201 | subpixel_order = SubPixelHorizontalRGB; |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | connector->display_info.subpixel_order = subpixel_order; |
| 1206 | drm_sysfs_connector_add(connector); |
| 1207 | return; |
| 1208 | |
| 1209 | failed: |
| 1210 | if (radeon_connector->ddc_bus) |
| 1211 | radeon_i2c_destroy(radeon_connector->ddc_bus); |
| 1212 | drm_connector_cleanup(connector); |
| 1213 | kfree(connector); |
| 1214 | } |
| 1215 | |
| 1216 | void |
| 1217 | radeon_add_legacy_connector(struct drm_device *dev, |
| 1218 | uint32_t connector_id, |
| 1219 | uint32_t supported_device, |
| 1220 | int connector_type, |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1221 | struct radeon_i2c_bus_rec *i2c_bus, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1222 | uint16_t connector_object_id, |
| 1223 | struct radeon_hpd *hpd) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1224 | { |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1225 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1226 | struct drm_connector *connector; |
| 1227 | struct radeon_connector *radeon_connector; |
| 1228 | uint32_t subpixel_order = SubPixelNone; |
| 1229 | |
| 1230 | /* fixme - tv/cv/din */ |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1231 | if (connector_type == DRM_MODE_CONNECTOR_Unknown) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1232 | return; |
| 1233 | |
| 1234 | /* see if we already added it */ |
| 1235 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 1236 | radeon_connector = to_radeon_connector(connector); |
| 1237 | if (radeon_connector->connector_id == connector_id) { |
| 1238 | radeon_connector->devices |= supported_device; |
| 1239 | return; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL); |
| 1244 | if (!radeon_connector) |
| 1245 | return; |
| 1246 | |
| 1247 | connector = &radeon_connector->base; |
| 1248 | |
| 1249 | radeon_connector->connector_id = connector_id; |
| 1250 | radeon_connector->devices = supported_device; |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1251 | radeon_connector->connector_object_id = connector_object_id; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1252 | radeon_connector->hpd = *hpd; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1253 | switch (connector_type) { |
| 1254 | case DRM_MODE_CONNECTOR_VGA: |
| 1255 | drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1256 | drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1257 | if (i2c_bus->valid) { |
| 1258 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); |
| 1259 | if (!radeon_connector->ddc_bus) |
| 1260 | goto failed; |
| 1261 | } |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1262 | radeon_connector->dac_load_detect = true; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1263 | drm_connector_attach_property(&radeon_connector->base, |
| 1264 | rdev->mode_info.load_detect_property, |
| 1265 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1266 | break; |
| 1267 | case DRM_MODE_CONNECTOR_DVIA: |
| 1268 | drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1269 | drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1270 | if (i2c_bus->valid) { |
| 1271 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); |
| 1272 | if (!radeon_connector->ddc_bus) |
| 1273 | goto failed; |
| 1274 | } |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1275 | radeon_connector->dac_load_detect = true; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1276 | drm_connector_attach_property(&radeon_connector->base, |
| 1277 | rdev->mode_info.load_detect_property, |
| 1278 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1279 | break; |
| 1280 | case DRM_MODE_CONNECTOR_DVII: |
| 1281 | case DRM_MODE_CONNECTOR_DVID: |
| 1282 | drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1283 | drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1284 | if (i2c_bus->valid) { |
| 1285 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); |
| 1286 | if (!radeon_connector->ddc_bus) |
| 1287 | goto failed; |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1288 | radeon_connector->dac_load_detect = true; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1289 | drm_connector_attach_property(&radeon_connector->base, |
| 1290 | rdev->mode_info.load_detect_property, |
| 1291 | 1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1292 | } |
| 1293 | subpixel_order = SubPixelHorizontalRGB; |
| 1294 | break; |
| 1295 | case DRM_MODE_CONNECTOR_SVIDEO: |
| 1296 | case DRM_MODE_CONNECTOR_Composite: |
| 1297 | case DRM_MODE_CONNECTOR_9PinDIN: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1298 | if (radeon_tv == 1) { |
| 1299 | drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1300 | drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs); |
Dave Airlie | 35e4b7a | 2009-09-25 11:56:50 +1000 | [diff] [blame] | 1301 | radeon_connector->dac_load_detect = true; |
Jerome Glisse | 0beb81a | 2009-11-13 20:56:35 +0100 | [diff] [blame] | 1302 | /* RS400,RC410,RS480 chipset seems to report a lot |
| 1303 | * of false positive on load detect, we haven't yet |
| 1304 | * found a way to make load detect reliable on those |
| 1305 | * chipset, thus just disable it for TV. |
| 1306 | */ |
| 1307 | if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) |
| 1308 | radeon_connector->dac_load_detect = false; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1309 | drm_connector_attach_property(&radeon_connector->base, |
| 1310 | rdev->mode_info.load_detect_property, |
Dave Airlie | 624ab4f | 2010-01-27 16:07:15 +1000 | [diff] [blame] | 1311 | radeon_connector->dac_load_detect); |
Alex Deucher | ed16014 | 2009-12-01 14:12:14 -0500 | [diff] [blame] | 1312 | drm_connector_attach_property(&radeon_connector->base, |
| 1313 | rdev->mode_info.tv_std_property, |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1314 | radeon_combios_get_tv_info(rdev)); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1315 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1316 | break; |
| 1317 | case DRM_MODE_CONNECTOR_LVDS: |
| 1318 | drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame^] | 1319 | drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1320 | if (i2c_bus->valid) { |
| 1321 | radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); |
| 1322 | if (!radeon_connector->ddc_bus) |
| 1323 | goto failed; |
| 1324 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1325 | drm_connector_attach_property(&radeon_connector->base, |
| 1326 | dev->mode_config.scaling_mode_property, |
| 1327 | DRM_MODE_SCALE_FULLSCREEN); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1328 | subpixel_order = SubPixelHorizontalRGB; |
| 1329 | break; |
| 1330 | } |
| 1331 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1332 | connector->display_info.subpixel_order = subpixel_order; |
| 1333 | drm_sysfs_connector_add(connector); |
| 1334 | return; |
| 1335 | |
| 1336 | failed: |
| 1337 | if (radeon_connector->ddc_bus) |
| 1338 | radeon_i2c_destroy(radeon_connector->ddc_bus); |
| 1339 | drm_connector_cleanup(connector); |
| 1340 | kfree(connector); |
| 1341 | } |