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