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