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