Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Maarten Maathuis. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
Ben Skeggs | a147089 | 2010-01-18 11:42:37 +1000 | [diff] [blame] | 27 | #include <acpi/button.h> |
| 28 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 29 | #include "drmP.h" |
| 30 | #include "drm_edid.h" |
| 31 | #include "drm_crtc_helper.h" |
Ben Skeggs | a147089 | 2010-01-18 11:42:37 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 33 | #include "nouveau_reg.h" |
| 34 | #include "nouveau_drv.h" |
| 35 | #include "nouveau_encoder.h" |
| 36 | #include "nouveau_crtc.h" |
| 37 | #include "nouveau_connector.h" |
| 38 | #include "nouveau_hw.h" |
| 39 | |
| 40 | static inline struct drm_encoder_slave_funcs * |
| 41 | get_slave_funcs(struct nouveau_encoder *enc) |
| 42 | { |
| 43 | return to_encoder_slave(to_drm_encoder(enc))->slave_funcs; |
| 44 | } |
| 45 | |
| 46 | static struct nouveau_encoder * |
| 47 | find_encoder_by_type(struct drm_connector *connector, int type) |
| 48 | { |
| 49 | struct drm_device *dev = connector->dev; |
| 50 | struct nouveau_encoder *nv_encoder; |
| 51 | struct drm_mode_object *obj; |
| 52 | int i, id; |
| 53 | |
| 54 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 55 | id = connector->encoder_ids[i]; |
| 56 | if (!id) |
| 57 | break; |
| 58 | |
| 59 | obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); |
| 60 | if (!obj) |
| 61 | continue; |
| 62 | nv_encoder = nouveau_encoder(obj_to_encoder(obj)); |
| 63 | |
| 64 | if (type == OUTPUT_ANY || nv_encoder->dcb->type == type) |
| 65 | return nv_encoder; |
| 66 | } |
| 67 | |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | struct nouveau_connector * |
| 72 | nouveau_encoder_connector_get(struct nouveau_encoder *encoder) |
| 73 | { |
| 74 | struct drm_device *dev = to_drm_encoder(encoder)->dev; |
| 75 | struct drm_connector *drm_connector; |
| 76 | |
| 77 | list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { |
| 78 | if (drm_connector->encoder == to_drm_encoder(encoder)) |
| 79 | return nouveau_connector(drm_connector); |
| 80 | } |
| 81 | |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | static void |
| 87 | nouveau_connector_destroy(struct drm_connector *drm_connector) |
| 88 | { |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 89 | struct nouveau_connector *nv_connector = |
| 90 | nouveau_connector(drm_connector); |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 91 | struct drm_device *dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 92 | |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 93 | if (!nv_connector) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 94 | return; |
| 95 | |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 96 | dev = nv_connector->base.dev; |
| 97 | NV_DEBUG_KMS(dev, "\n"); |
| 98 | |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 99 | kfree(nv_connector->edid); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 100 | drm_sysfs_connector_remove(drm_connector); |
| 101 | drm_connector_cleanup(drm_connector); |
| 102 | kfree(drm_connector); |
| 103 | } |
| 104 | |
| 105 | static void |
| 106 | nouveau_connector_ddc_prepare(struct drm_connector *connector, int *flags) |
| 107 | { |
| 108 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 109 | |
| 110 | if (dev_priv->card_type >= NV_50) |
| 111 | return; |
| 112 | |
| 113 | *flags = 0; |
| 114 | if (NVLockVgaCrtcs(dev_priv->dev, false)) |
| 115 | *flags |= 1; |
| 116 | if (nv_heads_tied(dev_priv->dev)) |
| 117 | *flags |= 2; |
| 118 | |
| 119 | if (*flags & 2) |
| 120 | NVSetOwner(dev_priv->dev, 0); /* necessary? */ |
| 121 | } |
| 122 | |
| 123 | static void |
| 124 | nouveau_connector_ddc_finish(struct drm_connector *connector, int flags) |
| 125 | { |
| 126 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 127 | |
| 128 | if (dev_priv->card_type >= NV_50) |
| 129 | return; |
| 130 | |
| 131 | if (flags & 2) |
| 132 | NVSetOwner(dev_priv->dev, 4); |
| 133 | if (flags & 1) |
| 134 | NVLockVgaCrtcs(dev_priv->dev, true); |
| 135 | } |
| 136 | |
| 137 | static struct nouveau_i2c_chan * |
| 138 | nouveau_connector_ddc_detect(struct drm_connector *connector, |
| 139 | struct nouveau_encoder **pnv_encoder) |
| 140 | { |
| 141 | struct drm_device *dev = connector->dev; |
| 142 | uint8_t out_buf[] = { 0x0, 0x0}, buf[2]; |
| 143 | int ret, flags, i; |
| 144 | |
| 145 | struct i2c_msg msgs[] = { |
| 146 | { |
| 147 | .addr = 0x50, |
| 148 | .flags = 0, |
| 149 | .len = 1, |
| 150 | .buf = out_buf, |
| 151 | }, |
| 152 | { |
| 153 | .addr = 0x50, |
| 154 | .flags = I2C_M_RD, |
| 155 | .len = 1, |
| 156 | .buf = buf, |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 161 | struct nouveau_i2c_chan *i2c = NULL; |
| 162 | struct nouveau_encoder *nv_encoder; |
| 163 | struct drm_mode_object *obj; |
| 164 | int id; |
| 165 | |
| 166 | id = connector->encoder_ids[i]; |
| 167 | if (!id) |
| 168 | break; |
| 169 | |
| 170 | obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); |
| 171 | if (!obj) |
| 172 | continue; |
| 173 | nv_encoder = nouveau_encoder(obj_to_encoder(obj)); |
| 174 | |
| 175 | if (nv_encoder->dcb->i2c_index < 0xf) |
| 176 | i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); |
| 177 | if (!i2c) |
| 178 | continue; |
| 179 | |
| 180 | nouveau_connector_ddc_prepare(connector, &flags); |
| 181 | ret = i2c_transfer(&i2c->adapter, msgs, 2); |
| 182 | nouveau_connector_ddc_finish(connector, flags); |
| 183 | |
| 184 | if (ret == 2) { |
| 185 | *pnv_encoder = nv_encoder; |
| 186 | return i2c; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | static void |
| 194 | nouveau_connector_set_encoder(struct drm_connector *connector, |
| 195 | struct nouveau_encoder *nv_encoder) |
| 196 | { |
| 197 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 198 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 199 | struct drm_device *dev = connector->dev; |
| 200 | |
| 201 | if (nv_connector->detected_encoder == nv_encoder) |
| 202 | return; |
| 203 | nv_connector->detected_encoder = nv_encoder; |
| 204 | |
| 205 | if (nv_encoder->dcb->type == OUTPUT_LVDS || |
| 206 | nv_encoder->dcb->type == OUTPUT_TMDS) { |
| 207 | connector->doublescan_allowed = false; |
| 208 | connector->interlace_allowed = false; |
| 209 | } else { |
| 210 | connector->doublescan_allowed = true; |
| 211 | if (dev_priv->card_type == NV_20 || |
| 212 | (dev_priv->card_type == NV_10 && |
| 213 | (dev->pci_device & 0x0ff0) != 0x0100 && |
| 214 | (dev->pci_device & 0x0ff0) != 0x0150)) |
| 215 | /* HW is broken */ |
| 216 | connector->interlace_allowed = false; |
| 217 | else |
| 218 | connector->interlace_allowed = true; |
| 219 | } |
| 220 | |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 221 | if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 222 | drm_connector_property_set_value(connector, |
| 223 | dev->mode_config.dvi_i_subconnector_property, |
| 224 | nv_encoder->dcb->type == OUTPUT_TMDS ? |
| 225 | DRM_MODE_SUBCONNECTOR_DVID : |
| 226 | DRM_MODE_SUBCONNECTOR_DVIA); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static enum drm_connector_status |
| 231 | nouveau_connector_detect(struct drm_connector *connector) |
| 232 | { |
| 233 | struct drm_device *dev = connector->dev; |
| 234 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 235 | struct nouveau_encoder *nv_encoder = NULL; |
| 236 | struct nouveau_i2c_chan *i2c; |
| 237 | int type, flags; |
| 238 | |
Francisco Jerez | b8780e2 | 2010-01-14 15:54:23 +0100 | [diff] [blame] | 239 | /* Cleanup the previous EDID block. */ |
| 240 | if (nv_connector->edid) { |
| 241 | drm_mode_connector_update_edid_property(connector, NULL); |
| 242 | kfree(nv_connector->edid); |
| 243 | nv_connector->edid = NULL; |
| 244 | } |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 245 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 246 | i2c = nouveau_connector_ddc_detect(connector, &nv_encoder); |
| 247 | if (i2c) { |
| 248 | nouveau_connector_ddc_prepare(connector, &flags); |
| 249 | nv_connector->edid = drm_get_edid(connector, &i2c->adapter); |
| 250 | nouveau_connector_ddc_finish(connector, flags); |
| 251 | drm_mode_connector_update_edid_property(connector, |
| 252 | nv_connector->edid); |
| 253 | if (!nv_connector->edid) { |
| 254 | NV_ERROR(dev, "DDC responded, but no EDID for %s\n", |
| 255 | drm_get_connector_name(connector)); |
Francisco Jerez | 0ed3165 | 2010-01-14 15:47:03 +0100 | [diff] [blame] | 256 | goto detect_analog; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (nv_encoder->dcb->type == OUTPUT_DP && |
| 260 | !nouveau_dp_detect(to_drm_encoder(nv_encoder))) { |
| 261 | NV_ERROR(dev, "Detected %s, but failed init\n", |
| 262 | drm_get_connector_name(connector)); |
| 263 | return connector_status_disconnected; |
| 264 | } |
| 265 | |
| 266 | /* Override encoder type for DVI-I based on whether EDID |
| 267 | * says the display is digital or analog, both use the |
| 268 | * same i2c channel so the value returned from ddc_detect |
| 269 | * isn't necessarily correct. |
| 270 | */ |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 271 | if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 272 | if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL) |
| 273 | type = OUTPUT_TMDS; |
| 274 | else |
| 275 | type = OUTPUT_ANALOG; |
| 276 | |
| 277 | nv_encoder = find_encoder_by_type(connector, type); |
| 278 | if (!nv_encoder) { |
| 279 | NV_ERROR(dev, "Detected %d encoder on %s, " |
| 280 | "but no object!\n", type, |
| 281 | drm_get_connector_name(connector)); |
| 282 | return connector_status_disconnected; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 287 | return connector_status_connected; |
| 288 | } |
| 289 | |
Francisco Jerez | 0ed3165 | 2010-01-14 15:47:03 +0100 | [diff] [blame] | 290 | detect_analog: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 291 | nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG); |
Ben Skeggs | f405350 | 2010-03-15 09:43:51 +1000 | [diff] [blame] | 292 | if (!nv_encoder && !nouveau_tv_disable) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 293 | nv_encoder = find_encoder_by_type(connector, OUTPUT_TV); |
| 294 | if (nv_encoder) { |
| 295 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
| 296 | struct drm_encoder_helper_funcs *helper = |
| 297 | encoder->helper_private; |
| 298 | |
| 299 | if (helper->detect(encoder, connector) == |
| 300 | connector_status_connected) { |
| 301 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 302 | return connector_status_connected; |
| 303 | } |
| 304 | |
| 305 | } |
| 306 | |
| 307 | return connector_status_disconnected; |
| 308 | } |
| 309 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 310 | static enum drm_connector_status |
| 311 | nouveau_connector_detect_lvds(struct drm_connector *connector) |
| 312 | { |
| 313 | struct drm_device *dev = connector->dev; |
| 314 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 315 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 316 | struct nouveau_encoder *nv_encoder = NULL; |
| 317 | enum drm_connector_status status = connector_status_disconnected; |
| 318 | |
| 319 | /* Cleanup the previous EDID block. */ |
| 320 | if (nv_connector->edid) { |
| 321 | drm_mode_connector_update_edid_property(connector, NULL); |
| 322 | kfree(nv_connector->edid); |
| 323 | nv_connector->edid = NULL; |
| 324 | } |
| 325 | |
| 326 | nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS); |
| 327 | if (!nv_encoder) |
| 328 | return connector_status_disconnected; |
| 329 | |
Ben Skeggs | a6ed76d | 2010-07-12 15:33:07 +1000 | [diff] [blame^] | 330 | /* Try retrieving EDID via DDC */ |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 331 | if (!dev_priv->vbios.fp_no_ddc) { |
| 332 | status = nouveau_connector_detect(connector); |
| 333 | if (status == connector_status_connected) |
| 334 | goto out; |
| 335 | } |
| 336 | |
Ben Skeggs | a6ed76d | 2010-07-12 15:33:07 +1000 | [diff] [blame^] | 337 | /* On some laptops (Sony, i'm looking at you) there appears to |
| 338 | * be no direct way of accessing the panel's EDID. The only |
| 339 | * option available to us appears to be to ask ACPI for help.. |
| 340 | * |
| 341 | * It's important this check's before trying straps, one of the |
| 342 | * said manufacturer's laptops are configured in such a way |
| 343 | * the nouveau decides an entry in the VBIOS FP mode table is |
| 344 | * valid - it's not (rh#613284) |
| 345 | */ |
| 346 | if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) { |
| 347 | if (!nouveau_acpi_edid(dev, connector)) { |
| 348 | status = connector_status_connected; |
| 349 | goto out; |
| 350 | } |
| 351 | } |
| 352 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 353 | /* If no EDID found above, and the VBIOS indicates a hardcoded |
| 354 | * modeline is avalilable for the panel, set it as the panel's |
| 355 | * native mode and exit. |
| 356 | */ |
| 357 | if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc || |
| 358 | nv_encoder->dcb->lvdsconf.use_straps_for_mode)) { |
| 359 | status = connector_status_connected; |
| 360 | goto out; |
| 361 | } |
| 362 | |
| 363 | /* Still nothing, some VBIOS images have a hardcoded EDID block |
| 364 | * stored for the panel stored in them. |
| 365 | */ |
| 366 | if (!dev_priv->vbios.fp_no_ddc) { |
| 367 | struct edid *edid = |
| 368 | (struct edid *)nouveau_bios_embedded_edid(dev); |
| 369 | if (edid) { |
| 370 | nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL); |
| 371 | *(nv_connector->edid) = *edid; |
| 372 | status = connector_status_connected; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | out: |
| 377 | #if defined(CONFIG_ACPI_BUTTON) || \ |
| 378 | (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE)) |
| 379 | if (status == connector_status_connected && |
| 380 | !nouveau_ignorelid && !acpi_lid_open()) |
| 381 | status = connector_status_unknown; |
| 382 | #endif |
| 383 | |
| 384 | drm_mode_connector_update_edid_property(connector, nv_connector->edid); |
Albert Damen | 3195c5f | 2010-06-20 16:57:57 +0200 | [diff] [blame] | 385 | nouveau_connector_set_encoder(connector, nv_encoder); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 386 | return status; |
| 387 | } |
| 388 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 389 | static void |
| 390 | nouveau_connector_force(struct drm_connector *connector) |
| 391 | { |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 392 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 393 | struct nouveau_encoder *nv_encoder; |
| 394 | int type; |
| 395 | |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 396 | if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 397 | if (connector->force == DRM_FORCE_ON_DIGITAL) |
| 398 | type = OUTPUT_TMDS; |
| 399 | else |
| 400 | type = OUTPUT_ANALOG; |
| 401 | } else |
| 402 | type = OUTPUT_ANY; |
| 403 | |
| 404 | nv_encoder = find_encoder_by_type(connector, type); |
| 405 | if (!nv_encoder) { |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 406 | NV_ERROR(connector->dev, "can't find encoder to force %s on!\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 407 | drm_get_connector_name(connector)); |
| 408 | connector->status = connector_status_disconnected; |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 413 | } |
| 414 | |
| 415 | static int |
| 416 | nouveau_connector_set_property(struct drm_connector *connector, |
| 417 | struct drm_property *property, uint64_t value) |
| 418 | { |
| 419 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 420 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
| 421 | struct drm_device *dev = connector->dev; |
| 422 | int ret; |
| 423 | |
| 424 | /* Scaling mode */ |
| 425 | if (property == dev->mode_config.scaling_mode_property) { |
| 426 | struct nouveau_crtc *nv_crtc = NULL; |
| 427 | bool modeset = false; |
| 428 | |
| 429 | switch (value) { |
| 430 | case DRM_MODE_SCALE_NONE: |
| 431 | case DRM_MODE_SCALE_FULLSCREEN: |
| 432 | case DRM_MODE_SCALE_CENTER: |
| 433 | case DRM_MODE_SCALE_ASPECT: |
| 434 | break; |
| 435 | default: |
| 436 | return -EINVAL; |
| 437 | } |
| 438 | |
| 439 | /* LVDS always needs gpu scaling */ |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 440 | if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS && |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 441 | value == DRM_MODE_SCALE_NONE) |
| 442 | return -EINVAL; |
| 443 | |
| 444 | /* Changing between GPU and panel scaling requires a full |
| 445 | * modeset |
| 446 | */ |
| 447 | if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) || |
| 448 | (value == DRM_MODE_SCALE_NONE)) |
| 449 | modeset = true; |
| 450 | nv_connector->scaling_mode = value; |
| 451 | |
| 452 | if (connector->encoder && connector->encoder->crtc) |
| 453 | nv_crtc = nouveau_crtc(connector->encoder->crtc); |
| 454 | if (!nv_crtc) |
| 455 | return 0; |
| 456 | |
| 457 | if (modeset || !nv_crtc->set_scale) { |
| 458 | ret = drm_crtc_helper_set_mode(&nv_crtc->base, |
| 459 | &nv_crtc->base.mode, |
| 460 | nv_crtc->base.x, |
| 461 | nv_crtc->base.y, NULL); |
| 462 | if (!ret) |
| 463 | return -EINVAL; |
| 464 | } else { |
| 465 | ret = nv_crtc->set_scale(nv_crtc, value, true); |
| 466 | if (ret) |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | /* Dithering */ |
| 474 | if (property == dev->mode_config.dithering_mode_property) { |
| 475 | struct nouveau_crtc *nv_crtc = NULL; |
| 476 | |
| 477 | if (value == DRM_MODE_DITHERING_ON) |
| 478 | nv_connector->use_dithering = true; |
| 479 | else |
| 480 | nv_connector->use_dithering = false; |
| 481 | |
| 482 | if (connector->encoder && connector->encoder->crtc) |
| 483 | nv_crtc = nouveau_crtc(connector->encoder->crtc); |
| 484 | |
| 485 | if (!nv_crtc || !nv_crtc->set_dither) |
| 486 | return 0; |
| 487 | |
| 488 | return nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering, |
| 489 | true); |
| 490 | } |
| 491 | |
| 492 | if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV) |
| 493 | return get_slave_funcs(nv_encoder)-> |
| 494 | set_property(to_drm_encoder(nv_encoder), connector, property, value); |
| 495 | |
| 496 | return -EINVAL; |
| 497 | } |
| 498 | |
| 499 | static struct drm_display_mode * |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 500 | nouveau_connector_native_mode(struct drm_connector *connector) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 501 | { |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 502 | struct drm_connector_helper_funcs *helper = connector->helper_private; |
| 503 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 504 | struct drm_device *dev = connector->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 505 | struct drm_display_mode *mode, *largest = NULL; |
| 506 | int high_w = 0, high_h = 0, high_v = 0; |
| 507 | |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 508 | list_for_each_entry(mode, &nv_connector->base.probed_modes, head) { |
| 509 | if (helper->mode_valid(connector, mode) != MODE_OK) |
| 510 | continue; |
| 511 | |
| 512 | /* Use preferred mode if there is one.. */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 513 | if (mode->type & DRM_MODE_TYPE_PREFERRED) { |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 514 | NV_DEBUG_KMS(dev, "native mode from preferred\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 515 | return drm_mode_duplicate(dev, mode); |
| 516 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 517 | |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 518 | /* Otherwise, take the resolution with the largest width, then |
| 519 | * height, then vertical refresh |
| 520 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 521 | if (mode->hdisplay < high_w) |
| 522 | continue; |
| 523 | |
| 524 | if (mode->hdisplay == high_w && mode->vdisplay < high_h) |
| 525 | continue; |
| 526 | |
| 527 | if (mode->hdisplay == high_w && mode->vdisplay == high_h && |
| 528 | mode->vrefresh < high_v) |
| 529 | continue; |
| 530 | |
| 531 | high_w = mode->hdisplay; |
| 532 | high_h = mode->vdisplay; |
| 533 | high_v = mode->vrefresh; |
| 534 | largest = mode; |
| 535 | } |
| 536 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 537 | NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 538 | high_w, high_h, high_v); |
| 539 | return largest ? drm_mode_duplicate(dev, largest) : NULL; |
| 540 | } |
| 541 | |
| 542 | struct moderec { |
| 543 | int hdisplay; |
| 544 | int vdisplay; |
| 545 | }; |
| 546 | |
| 547 | static struct moderec scaler_modes[] = { |
| 548 | { 1920, 1200 }, |
| 549 | { 1920, 1080 }, |
| 550 | { 1680, 1050 }, |
| 551 | { 1600, 1200 }, |
| 552 | { 1400, 1050 }, |
| 553 | { 1280, 1024 }, |
| 554 | { 1280, 960 }, |
| 555 | { 1152, 864 }, |
| 556 | { 1024, 768 }, |
| 557 | { 800, 600 }, |
| 558 | { 720, 400 }, |
| 559 | { 640, 480 }, |
| 560 | { 640, 400 }, |
| 561 | { 640, 350 }, |
| 562 | {} |
| 563 | }; |
| 564 | |
| 565 | static int |
| 566 | nouveau_connector_scaler_modes_add(struct drm_connector *connector) |
| 567 | { |
| 568 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 569 | struct drm_display_mode *native = nv_connector->native_mode, *m; |
| 570 | struct drm_device *dev = connector->dev; |
| 571 | struct moderec *mode = &scaler_modes[0]; |
| 572 | int modes = 0; |
| 573 | |
| 574 | if (!native) |
| 575 | return 0; |
| 576 | |
| 577 | while (mode->hdisplay) { |
| 578 | if (mode->hdisplay <= native->hdisplay && |
| 579 | mode->vdisplay <= native->vdisplay) { |
| 580 | m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay, |
| 581 | drm_mode_vrefresh(native), false, |
| 582 | false, false); |
| 583 | if (!m) |
| 584 | continue; |
| 585 | |
| 586 | m->type |= DRM_MODE_TYPE_DRIVER; |
| 587 | |
| 588 | drm_mode_probed_add(connector, m); |
| 589 | modes++; |
| 590 | } |
| 591 | |
| 592 | mode++; |
| 593 | } |
| 594 | |
| 595 | return modes; |
| 596 | } |
| 597 | |
| 598 | static int |
| 599 | nouveau_connector_get_modes(struct drm_connector *connector) |
| 600 | { |
| 601 | struct drm_device *dev = connector->dev; |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 602 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 603 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 604 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
| 605 | int ret = 0; |
| 606 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 607 | /* destroy the native mode, the attached monitor could have changed. |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 608 | */ |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 609 | if (nv_connector->native_mode) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 610 | drm_mode_destroy(dev, nv_connector->native_mode); |
| 611 | nv_connector->native_mode = NULL; |
| 612 | } |
| 613 | |
| 614 | if (nv_connector->edid) |
| 615 | ret = drm_add_edid_modes(connector, nv_connector->edid); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 616 | else |
| 617 | if (nv_encoder->dcb->type == OUTPUT_LVDS && |
| 618 | (nv_encoder->dcb->lvdsconf.use_straps_for_mode || |
Francisco Jerez | 6e86e04 | 2010-07-03 18:36:39 +0200 | [diff] [blame] | 619 | dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) { |
| 620 | nv_connector->native_mode = drm_mode_create(dev); |
| 621 | nouveau_bios_fp_mode(dev, nv_connector->native_mode); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 622 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 623 | |
| 624 | /* Find the native mode if this is a digital panel, if we didn't |
| 625 | * find any modes through DDC previously add the native mode to |
| 626 | * the list of modes. |
| 627 | */ |
| 628 | if (!nv_connector->native_mode) |
| 629 | nv_connector->native_mode = |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 630 | nouveau_connector_native_mode(connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 631 | if (ret == 0 && nv_connector->native_mode) { |
| 632 | struct drm_display_mode *mode; |
| 633 | |
| 634 | mode = drm_mode_duplicate(dev, nv_connector->native_mode); |
| 635 | drm_mode_probed_add(connector, mode); |
| 636 | ret = 1; |
| 637 | } |
| 638 | |
| 639 | if (nv_encoder->dcb->type == OUTPUT_TV) |
| 640 | ret = get_slave_funcs(nv_encoder)-> |
| 641 | get_modes(to_drm_encoder(nv_encoder), connector); |
| 642 | |
Ben Skeggs | 646bef2 | 2010-07-06 11:27:52 +1000 | [diff] [blame] | 643 | if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS || |
| 644 | nv_connector->dcb->type == DCB_CONNECTOR_eDP) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 645 | ret += nouveau_connector_scaler_modes_add(connector); |
| 646 | |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | static int |
| 651 | nouveau_connector_mode_valid(struct drm_connector *connector, |
| 652 | struct drm_display_mode *mode) |
| 653 | { |
| 654 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 655 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 656 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
| 657 | unsigned min_clock = 25000, max_clock = min_clock; |
| 658 | unsigned clock = mode->clock; |
| 659 | |
| 660 | switch (nv_encoder->dcb->type) { |
| 661 | case OUTPUT_LVDS: |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 662 | if (nv_connector->native_mode && |
| 663 | (mode->hdisplay > nv_connector->native_mode->hdisplay || |
| 664 | mode->vdisplay > nv_connector->native_mode->vdisplay)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 665 | return MODE_PANEL; |
| 666 | |
| 667 | min_clock = 0; |
| 668 | max_clock = 400000; |
| 669 | break; |
| 670 | case OUTPUT_TMDS: |
| 671 | if ((dev_priv->card_type >= NV_50 && !nouveau_duallink) || |
Ben Skeggs | 2c58077 | 2010-05-28 10:04:05 +1000 | [diff] [blame] | 672 | !nv_encoder->dcb->duallink_possible) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 673 | max_clock = 165000; |
| 674 | else |
| 675 | max_clock = 330000; |
| 676 | break; |
| 677 | case OUTPUT_ANALOG: |
| 678 | max_clock = nv_encoder->dcb->crtconf.maxfreq; |
| 679 | if (!max_clock) |
| 680 | max_clock = 350000; |
| 681 | break; |
| 682 | case OUTPUT_TV: |
| 683 | return get_slave_funcs(nv_encoder)-> |
| 684 | mode_valid(to_drm_encoder(nv_encoder), mode); |
| 685 | case OUTPUT_DP: |
| 686 | if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7) |
| 687 | max_clock = nv_encoder->dp.link_nr * 270000; |
| 688 | else |
| 689 | max_clock = nv_encoder->dp.link_nr * 162000; |
| 690 | |
| 691 | clock *= 3; |
| 692 | break; |
Ben Skeggs | e7cc51c | 2010-02-24 10:31:39 +1000 | [diff] [blame] | 693 | default: |
| 694 | BUG_ON(1); |
| 695 | return MODE_BAD; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | if (clock < min_clock) |
| 699 | return MODE_CLOCK_LOW; |
| 700 | |
| 701 | if (clock > max_clock) |
| 702 | return MODE_CLOCK_HIGH; |
| 703 | |
| 704 | return MODE_OK; |
| 705 | } |
| 706 | |
| 707 | static struct drm_encoder * |
| 708 | nouveau_connector_best_encoder(struct drm_connector *connector) |
| 709 | { |
| 710 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 711 | |
| 712 | if (nv_connector->detected_encoder) |
| 713 | return to_drm_encoder(nv_connector->detected_encoder); |
| 714 | |
| 715 | return NULL; |
| 716 | } |
| 717 | |
Francisco Jerez | 2ed06b7 | 2010-07-03 15:52:03 +0200 | [diff] [blame] | 718 | void |
| 719 | nouveau_connector_set_polling(struct drm_connector *connector) |
| 720 | { |
| 721 | struct drm_device *dev = connector->dev; |
| 722 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 723 | struct drm_crtc *crtc; |
| 724 | bool spare_crtc = false; |
| 725 | |
| 726 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 727 | spare_crtc |= !crtc->enabled; |
| 728 | |
| 729 | connector->polled = 0; |
| 730 | |
| 731 | switch (connector->connector_type) { |
| 732 | case DRM_MODE_CONNECTOR_VGA: |
| 733 | case DRM_MODE_CONNECTOR_TV: |
| 734 | if (dev_priv->card_type >= NV_50 || |
| 735 | (nv_gf4_disp_arch(dev) && spare_crtc)) |
| 736 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
| 737 | break; |
| 738 | |
| 739 | case DRM_MODE_CONNECTOR_DVII: |
| 740 | case DRM_MODE_CONNECTOR_DVID: |
| 741 | case DRM_MODE_CONNECTOR_HDMIA: |
| 742 | case DRM_MODE_CONNECTOR_DisplayPort: |
| 743 | case DRM_MODE_CONNECTOR_eDP: |
| 744 | if (dev_priv->card_type >= NV_50) |
| 745 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 746 | else if (connector->connector_type == DRM_MODE_CONNECTOR_DVID || |
| 747 | spare_crtc) |
| 748 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
| 749 | break; |
| 750 | |
| 751 | default: |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 756 | static const struct drm_connector_helper_funcs |
| 757 | nouveau_connector_helper_funcs = { |
| 758 | .get_modes = nouveau_connector_get_modes, |
| 759 | .mode_valid = nouveau_connector_mode_valid, |
| 760 | .best_encoder = nouveau_connector_best_encoder, |
| 761 | }; |
| 762 | |
| 763 | static const struct drm_connector_funcs |
| 764 | nouveau_connector_funcs = { |
| 765 | .dpms = drm_helper_connector_dpms, |
| 766 | .save = NULL, |
| 767 | .restore = NULL, |
| 768 | .detect = nouveau_connector_detect, |
| 769 | .destroy = nouveau_connector_destroy, |
| 770 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 771 | .set_property = nouveau_connector_set_property, |
| 772 | .force = nouveau_connector_force |
| 773 | }; |
| 774 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 775 | static const struct drm_connector_funcs |
| 776 | nouveau_connector_funcs_lvds = { |
| 777 | .dpms = drm_helper_connector_dpms, |
| 778 | .save = NULL, |
| 779 | .restore = NULL, |
| 780 | .detect = nouveau_connector_detect_lvds, |
| 781 | .destroy = nouveau_connector_destroy, |
| 782 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 783 | .set_property = nouveau_connector_set_property, |
| 784 | .force = nouveau_connector_force |
| 785 | }; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 786 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 787 | struct drm_connector * |
| 788 | nouveau_connector_create(struct drm_device *dev, int index) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 789 | { |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 790 | const struct drm_connector_funcs *funcs = &nouveau_connector_funcs; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 791 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 792 | struct nouveau_connector *nv_connector = NULL; |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 793 | struct dcb_connector_table_entry *dcb = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 794 | struct drm_connector *connector; |
Francisco Jerez | 2fa67f1 | 2010-06-16 15:52:44 +0200 | [diff] [blame] | 795 | int type, ret = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 796 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 797 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 798 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 799 | if (index >= dev_priv->vbios.dcb.connector.entries) |
| 800 | return ERR_PTR(-EINVAL); |
| 801 | |
| 802 | dcb = &dev_priv->vbios.dcb.connector.entry[index]; |
| 803 | if (dcb->drm) |
| 804 | return dcb->drm; |
| 805 | |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 806 | switch (dcb->type) { |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 807 | case DCB_CONNECTOR_VGA: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 808 | type = DRM_MODE_CONNECTOR_VGA; |
| 809 | break; |
| 810 | case DCB_CONNECTOR_TV_0: |
| 811 | case DCB_CONNECTOR_TV_1: |
| 812 | case DCB_CONNECTOR_TV_3: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 813 | type = DRM_MODE_CONNECTOR_TV; |
| 814 | break; |
| 815 | case DCB_CONNECTOR_DVI_I: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 816 | type = DRM_MODE_CONNECTOR_DVII; |
| 817 | break; |
| 818 | case DCB_CONNECTOR_DVI_D: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 819 | type = DRM_MODE_CONNECTOR_DVID; |
| 820 | break; |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 821 | case DCB_CONNECTOR_HDMI_0: |
| 822 | case DCB_CONNECTOR_HDMI_1: |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 823 | type = DRM_MODE_CONNECTOR_HDMIA; |
| 824 | break; |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 825 | case DCB_CONNECTOR_LVDS: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 826 | type = DRM_MODE_CONNECTOR_LVDS; |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 827 | funcs = &nouveau_connector_funcs_lvds; |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 828 | break; |
| 829 | case DCB_CONNECTOR_DP: |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 830 | type = DRM_MODE_CONNECTOR_DisplayPort; |
| 831 | break; |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 832 | case DCB_CONNECTOR_eDP: |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 833 | type = DRM_MODE_CONNECTOR_eDP; |
| 834 | break; |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 835 | default: |
| 836 | NV_ERROR(dev, "unknown connector type: 0x%02x!!\n", dcb->type); |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 837 | return ERR_PTR(-EINVAL); |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 838 | } |
| 839 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 840 | nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL); |
| 841 | if (!nv_connector) |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 842 | return ERR_PTR(-ENOMEM); |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 843 | nv_connector->dcb = dcb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 844 | connector = &nv_connector->base; |
| 845 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 846 | /* defaults, will get overridden in detect() */ |
| 847 | connector->interlace_allowed = false; |
| 848 | connector->doublescan_allowed = false; |
| 849 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 850 | drm_connector_init(dev, connector, funcs, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 851 | drm_connector_helper_add(connector, &nouveau_connector_helper_funcs); |
| 852 | |
Francisco Jerez | 2fa67f1 | 2010-06-16 15:52:44 +0200 | [diff] [blame] | 853 | /* Check if we need dithering enabled */ |
| 854 | if (dcb->type == DCB_CONNECTOR_LVDS) { |
| 855 | bool dummy, is_24bit = false; |
| 856 | |
| 857 | ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &is_24bit); |
| 858 | if (ret) { |
| 859 | NV_ERROR(dev, "Error parsing LVDS table, disabling " |
| 860 | "LVDS\n"); |
| 861 | goto fail; |
| 862 | } |
| 863 | |
| 864 | nv_connector->use_dithering = !is_24bit; |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 865 | } |
| 866 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 867 | /* Init DVI-I specific properties */ |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 868 | if (dcb->type == DCB_CONNECTOR_DVI_I) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 869 | drm_mode_create_dvi_i_properties(dev); |
| 870 | drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0); |
| 871 | drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0); |
| 872 | } |
| 873 | |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 874 | switch (dcb->type) { |
| 875 | case DCB_CONNECTOR_VGA: |
| 876 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 877 | drm_connector_attach_property(connector, |
| 878 | dev->mode_config.scaling_mode_property, |
| 879 | nv_connector->scaling_mode); |
| 880 | } |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 881 | /* fall-through */ |
| 882 | case DCB_CONNECTOR_TV_0: |
| 883 | case DCB_CONNECTOR_TV_1: |
| 884 | case DCB_CONNECTOR_TV_3: |
| 885 | nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; |
| 886 | break; |
| 887 | default: |
| 888 | nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; |
| 889 | |
| 890 | drm_connector_attach_property(connector, |
| 891 | dev->mode_config.scaling_mode_property, |
| 892 | nv_connector->scaling_mode); |
| 893 | drm_connector_attach_property(connector, |
| 894 | dev->mode_config.dithering_mode_property, |
| 895 | nv_connector->use_dithering ? |
| 896 | DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF); |
| 897 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 898 | } |
| 899 | |
Francisco Jerez | 2ed06b7 | 2010-07-03 15:52:03 +0200 | [diff] [blame] | 900 | nouveau_connector_set_polling(connector); |
| 901 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 902 | drm_sysfs_connector_add(connector); |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 903 | dcb->drm = connector; |
| 904 | return dcb->drm; |
Francisco Jerez | 2fa67f1 | 2010-06-16 15:52:44 +0200 | [diff] [blame] | 905 | |
| 906 | fail: |
| 907 | drm_connector_cleanup(connector); |
| 908 | kfree(connector); |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 909 | return ERR_PTR(ret); |
Francisco Jerez | 2fa67f1 | 2010-06-16 15:52:44 +0200 | [diff] [blame] | 910 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 911 | } |