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 | 10b461e | 2011-08-02 19:29:37 +1000 | [diff] [blame] | 42 | struct nouveau_encoder * |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 43 | find_encoder(struct drm_connector *connector, int type) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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) { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 115 | pgpio->irq_unregister(dev, nv_connector->hpd, |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 116 | nouveau_connector_hotplug, connector); |
| 117 | } |
| 118 | |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 119 | kfree(nv_connector->edid); |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 120 | drm_sysfs_connector_remove(connector); |
| 121 | drm_connector_cleanup(connector); |
| 122 | kfree(connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 123 | } |
| 124 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 125 | static struct nouveau_i2c_chan * |
| 126 | nouveau_connector_ddc_detect(struct drm_connector *connector, |
| 127 | struct nouveau_encoder **pnv_encoder) |
| 128 | { |
| 129 | struct drm_device *dev = connector->dev; |
Francisco Jerez | 03cd06c | 2010-07-20 03:08:25 +0200 | [diff] [blame] | 130 | int i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 131 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 132 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
Francisco Jerez | 4ca2b71 | 2010-08-08 21:35:57 +0200 | [diff] [blame] | 133 | struct nouveau_i2c_chan *i2c = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 134 | struct nouveau_encoder *nv_encoder; |
| 135 | struct drm_mode_object *obj; |
| 136 | int id; |
| 137 | |
| 138 | id = connector->encoder_ids[i]; |
| 139 | if (!id) |
| 140 | break; |
| 141 | |
| 142 | obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); |
| 143 | if (!obj) |
| 144 | continue; |
| 145 | nv_encoder = nouveau_encoder(obj_to_encoder(obj)); |
Francisco Jerez | 4ca2b71 | 2010-08-08 21:35:57 +0200 | [diff] [blame] | 146 | |
| 147 | if (nv_encoder->dcb->i2c_index < 0xf) |
| 148 | i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 149 | |
Francisco Jerez | 03cd06c | 2010-07-20 03:08:25 +0200 | [diff] [blame] | 150 | if (i2c && nouveau_probe_i2c_addr(i2c, 0x50)) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 151 | *pnv_encoder = nv_encoder; |
| 152 | return i2c; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return NULL; |
| 157 | } |
| 158 | |
Francisco Jerez | c16c570 | 2010-09-09 14:33:17 +0200 | [diff] [blame] | 159 | static struct nouveau_encoder * |
| 160 | nouveau_connector_of_detect(struct drm_connector *connector) |
| 161 | { |
| 162 | #ifdef __powerpc__ |
| 163 | struct drm_device *dev = connector->dev; |
| 164 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 165 | struct nouveau_encoder *nv_encoder; |
| 166 | struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev); |
| 167 | |
| 168 | if (!dn || |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 169 | !((nv_encoder = find_encoder(connector, OUTPUT_TMDS)) || |
| 170 | (nv_encoder = find_encoder(connector, OUTPUT_ANALOG)))) |
Francisco Jerez | c16c570 | 2010-09-09 14:33:17 +0200 | [diff] [blame] | 171 | return NULL; |
| 172 | |
| 173 | for_each_child_of_node(dn, cn) { |
| 174 | const char *name = of_get_property(cn, "name", NULL); |
| 175 | const void *edid = of_get_property(cn, "EDID", NULL); |
| 176 | int idx = name ? name[strlen(name) - 1] - 'A' : 0; |
| 177 | |
| 178 | if (nv_encoder->dcb->i2c_index == idx && edid) { |
| 179 | nv_connector->edid = |
| 180 | kmemdup(edid, EDID_LENGTH, GFP_KERNEL); |
| 181 | of_node_put(cn); |
| 182 | return nv_encoder; |
| 183 | } |
| 184 | } |
| 185 | #endif |
| 186 | return NULL; |
| 187 | } |
| 188 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 189 | static void |
| 190 | nouveau_connector_set_encoder(struct drm_connector *connector, |
| 191 | struct nouveau_encoder *nv_encoder) |
| 192 | { |
| 193 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 194 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 195 | struct drm_device *dev = connector->dev; |
| 196 | |
| 197 | if (nv_connector->detected_encoder == nv_encoder) |
| 198 | return; |
| 199 | nv_connector->detected_encoder = nv_encoder; |
| 200 | |
Ben Skeggs | c833442 | 2011-10-19 13:06:48 +1000 | [diff] [blame] | 201 | if (dev_priv->card_type >= NV_50) { |
| 202 | connector->interlace_allowed = true; |
| 203 | connector->doublescan_allowed = true; |
| 204 | } else |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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 | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 221 | if (nv_connector->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; |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 236 | struct nouveau_encoder *nv_partner; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 237 | struct nouveau_i2c_chan *i2c; |
Francisco Jerez | 03cd06c | 2010-07-20 03:08:25 +0200 | [diff] [blame] | 238 | int type; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 239 | |
Francisco Jerez | b8780e2 | 2010-01-14 15:54:23 +0100 | [diff] [blame] | 240 | /* Cleanup the previous EDID block. */ |
| 241 | if (nv_connector->edid) { |
| 242 | drm_mode_connector_update_edid_property(connector, NULL); |
| 243 | kfree(nv_connector->edid); |
| 244 | nv_connector->edid = NULL; |
| 245 | } |
Xavier Chantry | c8ebe27 | 2010-01-11 22:42:21 +0100 | [diff] [blame] | 246 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 247 | i2c = nouveau_connector_ddc_detect(connector, &nv_encoder); |
| 248 | if (i2c) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | nv_connector->edid = drm_get_edid(connector, &i2c->adapter); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 250 | drm_mode_connector_update_edid_property(connector, |
| 251 | nv_connector->edid); |
| 252 | if (!nv_connector->edid) { |
| 253 | NV_ERROR(dev, "DDC responded, but no EDID for %s\n", |
| 254 | drm_get_connector_name(connector)); |
Francisco Jerez | 0ed3165 | 2010-01-14 15:47:03 +0100 | [diff] [blame] | 255 | goto detect_analog; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | if (nv_encoder->dcb->type == OUTPUT_DP && |
| 259 | !nouveau_dp_detect(to_drm_encoder(nv_encoder))) { |
| 260 | NV_ERROR(dev, "Detected %s, but failed init\n", |
| 261 | drm_get_connector_name(connector)); |
| 262 | return connector_status_disconnected; |
| 263 | } |
| 264 | |
| 265 | /* Override encoder type for DVI-I based on whether EDID |
| 266 | * says the display is digital or analog, both use the |
| 267 | * same i2c channel so the value returned from ddc_detect |
| 268 | * isn't necessarily correct. |
| 269 | */ |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 270 | nv_partner = NULL; |
| 271 | if (nv_encoder->dcb->type == OUTPUT_TMDS) |
| 272 | nv_partner = find_encoder(connector, OUTPUT_ANALOG); |
| 273 | if (nv_encoder->dcb->type == OUTPUT_ANALOG) |
| 274 | nv_partner = find_encoder(connector, OUTPUT_TMDS); |
| 275 | |
| 276 | if (nv_partner && ((nv_encoder->dcb->type == OUTPUT_ANALOG && |
| 277 | nv_partner->dcb->type == OUTPUT_TMDS) || |
| 278 | (nv_encoder->dcb->type == OUTPUT_TMDS && |
| 279 | nv_partner->dcb->type == OUTPUT_ANALOG))) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 280 | if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL) |
| 281 | type = OUTPUT_TMDS; |
| 282 | else |
| 283 | type = OUTPUT_ANALOG; |
| 284 | |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 285 | nv_encoder = find_encoder(connector, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 289 | return connector_status_connected; |
| 290 | } |
| 291 | |
Francisco Jerez | c16c570 | 2010-09-09 14:33:17 +0200 | [diff] [blame] | 292 | nv_encoder = nouveau_connector_of_detect(connector); |
| 293 | if (nv_encoder) { |
| 294 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 295 | return connector_status_connected; |
| 296 | } |
| 297 | |
Francisco Jerez | 0ed3165 | 2010-01-14 15:47:03 +0100 | [diff] [blame] | 298 | detect_analog: |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 299 | nv_encoder = find_encoder(connector, OUTPUT_ANALOG); |
Ben Skeggs | f405350 | 2010-03-15 09:43:51 +1000 | [diff] [blame] | 300 | if (!nv_encoder && !nouveau_tv_disable) |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 301 | nv_encoder = find_encoder(connector, OUTPUT_TV); |
Francisco Jerez | 84b8081 | 2010-10-26 02:17:56 +0200 | [diff] [blame] | 302 | if (nv_encoder && force) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 303 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
| 304 | struct drm_encoder_helper_funcs *helper = |
| 305 | encoder->helper_private; |
| 306 | |
| 307 | if (helper->detect(encoder, connector) == |
| 308 | connector_status_connected) { |
| 309 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 310 | return connector_status_connected; |
| 311 | } |
| 312 | |
| 313 | } |
| 314 | |
| 315 | return connector_status_disconnected; |
| 316 | } |
| 317 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 318 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 319 | nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 320 | { |
| 321 | struct drm_device *dev = connector->dev; |
| 322 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 323 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 324 | struct nouveau_encoder *nv_encoder = NULL; |
| 325 | enum drm_connector_status status = connector_status_disconnected; |
| 326 | |
| 327 | /* Cleanup the previous EDID block. */ |
| 328 | if (nv_connector->edid) { |
| 329 | drm_mode_connector_update_edid_property(connector, NULL); |
| 330 | kfree(nv_connector->edid); |
| 331 | nv_connector->edid = NULL; |
| 332 | } |
| 333 | |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 334 | nv_encoder = find_encoder(connector, OUTPUT_LVDS); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 335 | if (!nv_encoder) |
| 336 | return connector_status_disconnected; |
| 337 | |
Ben Skeggs | a6ed76d | 2010-07-12 15:33:07 +1000 | [diff] [blame] | 338 | /* Try retrieving EDID via DDC */ |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 339 | if (!dev_priv->vbios.fp_no_ddc) { |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 340 | status = nouveau_connector_detect(connector, force); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 341 | if (status == connector_status_connected) |
| 342 | goto out; |
| 343 | } |
| 344 | |
Ben Skeggs | a6ed76d | 2010-07-12 15:33:07 +1000 | [diff] [blame] | 345 | /* On some laptops (Sony, i'm looking at you) there appears to |
| 346 | * be no direct way of accessing the panel's EDID. The only |
| 347 | * option available to us appears to be to ask ACPI for help.. |
| 348 | * |
| 349 | * It's important this check's before trying straps, one of the |
| 350 | * said manufacturer's laptops are configured in such a way |
| 351 | * the nouveau decides an entry in the VBIOS FP mode table is |
| 352 | * valid - it's not (rh#613284) |
| 353 | */ |
| 354 | if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) { |
| 355 | if (!nouveau_acpi_edid(dev, connector)) { |
| 356 | status = connector_status_connected; |
| 357 | goto out; |
| 358 | } |
| 359 | } |
| 360 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 361 | /* If no EDID found above, and the VBIOS indicates a hardcoded |
| 362 | * modeline is avalilable for the panel, set it as the panel's |
| 363 | * native mode and exit. |
| 364 | */ |
| 365 | if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc || |
| 366 | nv_encoder->dcb->lvdsconf.use_straps_for_mode)) { |
| 367 | status = connector_status_connected; |
| 368 | goto out; |
| 369 | } |
| 370 | |
| 371 | /* Still nothing, some VBIOS images have a hardcoded EDID block |
| 372 | * stored for the panel stored in them. |
| 373 | */ |
| 374 | if (!dev_priv->vbios.fp_no_ddc) { |
| 375 | struct edid *edid = |
| 376 | (struct edid *)nouveau_bios_embedded_edid(dev); |
| 377 | if (edid) { |
| 378 | nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL); |
| 379 | *(nv_connector->edid) = *edid; |
| 380 | status = connector_status_connected; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | out: |
| 385 | #if defined(CONFIG_ACPI_BUTTON) || \ |
| 386 | (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE)) |
| 387 | if (status == connector_status_connected && |
| 388 | !nouveau_ignorelid && !acpi_lid_open()) |
| 389 | status = connector_status_unknown; |
| 390 | #endif |
| 391 | |
| 392 | drm_mode_connector_update_edid_property(connector, nv_connector->edid); |
Albert Damen | 3195c5f | 2010-06-20 16:57:57 +0200 | [diff] [blame] | 393 | nouveau_connector_set_encoder(connector, nv_encoder); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 394 | return status; |
| 395 | } |
| 396 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 397 | static void |
| 398 | nouveau_connector_force(struct drm_connector *connector) |
| 399 | { |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 400 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 401 | struct nouveau_encoder *nv_encoder; |
| 402 | int type; |
| 403 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 404 | if (nv_connector->type == DCB_CONNECTOR_DVI_I) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 405 | if (connector->force == DRM_FORCE_ON_DIGITAL) |
| 406 | type = OUTPUT_TMDS; |
| 407 | else |
| 408 | type = OUTPUT_ANALOG; |
| 409 | } else |
| 410 | type = OUTPUT_ANY; |
| 411 | |
Ben Skeggs | e19b20b | 2011-07-12 13:32:07 +1000 | [diff] [blame] | 412 | nv_encoder = find_encoder(connector, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 413 | if (!nv_encoder) { |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 414 | 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] | 415 | drm_get_connector_name(connector)); |
| 416 | connector->status = connector_status_disconnected; |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | nouveau_connector_set_encoder(connector, nv_encoder); |
| 421 | } |
| 422 | |
| 423 | static int |
| 424 | nouveau_connector_set_property(struct drm_connector *connector, |
| 425 | struct drm_property *property, uint64_t value) |
| 426 | { |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 427 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 428 | struct nouveau_display_engine *disp = &dev_priv->engine.display; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 430 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 431 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 432 | struct drm_device *dev = connector->dev; |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 433 | struct nouveau_crtc *nv_crtc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 434 | int ret; |
| 435 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 436 | nv_crtc = NULL; |
| 437 | if (connector->encoder && connector->encoder->crtc) |
| 438 | nv_crtc = nouveau_crtc(connector->encoder->crtc); |
| 439 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 440 | /* Scaling mode */ |
| 441 | if (property == dev->mode_config.scaling_mode_property) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 442 | bool modeset = false; |
| 443 | |
| 444 | switch (value) { |
| 445 | case DRM_MODE_SCALE_NONE: |
| 446 | case DRM_MODE_SCALE_FULLSCREEN: |
| 447 | case DRM_MODE_SCALE_CENTER: |
| 448 | case DRM_MODE_SCALE_ASPECT: |
| 449 | break; |
| 450 | default: |
| 451 | return -EINVAL; |
| 452 | } |
| 453 | |
| 454 | /* LVDS always needs gpu scaling */ |
Ben Skeggs | 8c3f6bb | 2011-04-18 09:57:48 +1000 | [diff] [blame] | 455 | if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS && |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 456 | value == DRM_MODE_SCALE_NONE) |
| 457 | return -EINVAL; |
| 458 | |
| 459 | /* Changing between GPU and panel scaling requires a full |
| 460 | * modeset |
| 461 | */ |
| 462 | if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) || |
| 463 | (value == DRM_MODE_SCALE_NONE)) |
| 464 | modeset = true; |
| 465 | nv_connector->scaling_mode = value; |
| 466 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 467 | if (!nv_crtc) |
| 468 | return 0; |
| 469 | |
| 470 | if (modeset || !nv_crtc->set_scale) { |
| 471 | ret = drm_crtc_helper_set_mode(&nv_crtc->base, |
| 472 | &nv_crtc->base.mode, |
| 473 | nv_crtc->base.x, |
| 474 | nv_crtc->base.y, NULL); |
| 475 | if (!ret) |
| 476 | return -EINVAL; |
| 477 | } else { |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 478 | ret = nv_crtc->set_scale(nv_crtc, true); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 479 | if (ret) |
| 480 | return ret; |
| 481 | } |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 486 | /* Underscan */ |
| 487 | if (property == disp->underscan_property) { |
| 488 | if (nv_connector->underscan != value) { |
| 489 | nv_connector->underscan = value; |
| 490 | if (!nv_crtc || !nv_crtc->set_scale) |
| 491 | return 0; |
| 492 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 493 | return nv_crtc->set_scale(nv_crtc, true); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | if (property == disp->underscan_hborder_property) { |
| 500 | if (nv_connector->underscan_hborder != value) { |
| 501 | nv_connector->underscan_hborder = value; |
| 502 | if (!nv_crtc || !nv_crtc->set_scale) |
| 503 | return 0; |
| 504 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 505 | return nv_crtc->set_scale(nv_crtc, true); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | if (property == disp->underscan_vborder_property) { |
| 512 | if (nv_connector->underscan_vborder != value) { |
| 513 | nv_connector->underscan_vborder = value; |
| 514 | if (!nv_crtc || !nv_crtc->set_scale) |
| 515 | return 0; |
| 516 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 517 | return nv_crtc->set_scale(nv_crtc, true); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 523 | /* Dithering */ |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 524 | if (property == disp->dithering_mode) { |
| 525 | nv_connector->dithering_mode = value; |
| 526 | if (!nv_crtc || !nv_crtc->set_dither) |
| 527 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 528 | |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 529 | return nv_crtc->set_dither(nv_crtc, true); |
| 530 | } |
| 531 | |
| 532 | if (property == disp->dithering_depth) { |
| 533 | nv_connector->dithering_depth = value; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 534 | if (!nv_crtc || !nv_crtc->set_dither) |
| 535 | return 0; |
| 536 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 537 | return nv_crtc->set_dither(nv_crtc, true); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV) |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 541 | return get_slave_funcs(encoder)->set_property( |
| 542 | encoder, connector, property, value); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 543 | |
| 544 | return -EINVAL; |
| 545 | } |
| 546 | |
| 547 | static struct drm_display_mode * |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 548 | nouveau_connector_native_mode(struct drm_connector *connector) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 549 | { |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 550 | struct drm_connector_helper_funcs *helper = connector->helper_private; |
| 551 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 552 | struct drm_device *dev = connector->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 553 | struct drm_display_mode *mode, *largest = NULL; |
| 554 | int high_w = 0, high_h = 0, high_v = 0; |
| 555 | |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 556 | list_for_each_entry(mode, &nv_connector->base.probed_modes, head) { |
Ben Skeggs | 0d9b619 | 2011-02-07 08:41:18 +1000 | [diff] [blame] | 557 | mode->vrefresh = drm_mode_vrefresh(mode); |
Francisco Jerez | a5afb77 | 2010-07-18 16:19:16 +0200 | [diff] [blame] | 558 | if (helper->mode_valid(connector, mode) != MODE_OK || |
| 559 | (mode->flags & DRM_MODE_FLAG_INTERLACE)) |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 560 | continue; |
| 561 | |
| 562 | /* Use preferred mode if there is one.. */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 563 | if (mode->type & DRM_MODE_TYPE_PREFERRED) { |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 564 | NV_DEBUG_KMS(dev, "native mode from preferred\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 565 | return drm_mode_duplicate(dev, mode); |
| 566 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 567 | |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 568 | /* Otherwise, take the resolution with the largest width, then |
| 569 | * height, then vertical refresh |
| 570 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 571 | if (mode->hdisplay < high_w) |
| 572 | continue; |
| 573 | |
| 574 | if (mode->hdisplay == high_w && mode->vdisplay < high_h) |
| 575 | continue; |
| 576 | |
| 577 | if (mode->hdisplay == high_w && mode->vdisplay == high_h && |
| 578 | mode->vrefresh < high_v) |
| 579 | continue; |
| 580 | |
| 581 | high_w = mode->hdisplay; |
| 582 | high_h = mode->vdisplay; |
| 583 | high_v = mode->vrefresh; |
| 584 | largest = mode; |
| 585 | } |
| 586 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 587 | NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 588 | high_w, high_h, high_v); |
| 589 | return largest ? drm_mode_duplicate(dev, largest) : NULL; |
| 590 | } |
| 591 | |
| 592 | struct moderec { |
| 593 | int hdisplay; |
| 594 | int vdisplay; |
| 595 | }; |
| 596 | |
| 597 | static struct moderec scaler_modes[] = { |
| 598 | { 1920, 1200 }, |
| 599 | { 1920, 1080 }, |
| 600 | { 1680, 1050 }, |
| 601 | { 1600, 1200 }, |
| 602 | { 1400, 1050 }, |
| 603 | { 1280, 1024 }, |
| 604 | { 1280, 960 }, |
| 605 | { 1152, 864 }, |
| 606 | { 1024, 768 }, |
| 607 | { 800, 600 }, |
| 608 | { 720, 400 }, |
| 609 | { 640, 480 }, |
| 610 | { 640, 400 }, |
| 611 | { 640, 350 }, |
| 612 | {} |
| 613 | }; |
| 614 | |
| 615 | static int |
| 616 | nouveau_connector_scaler_modes_add(struct drm_connector *connector) |
| 617 | { |
| 618 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 619 | struct drm_display_mode *native = nv_connector->native_mode, *m; |
| 620 | struct drm_device *dev = connector->dev; |
| 621 | struct moderec *mode = &scaler_modes[0]; |
| 622 | int modes = 0; |
| 623 | |
| 624 | if (!native) |
| 625 | return 0; |
| 626 | |
| 627 | while (mode->hdisplay) { |
| 628 | if (mode->hdisplay <= native->hdisplay && |
| 629 | mode->vdisplay <= native->vdisplay) { |
| 630 | m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay, |
| 631 | drm_mode_vrefresh(native), false, |
| 632 | false, false); |
| 633 | if (!m) |
| 634 | continue; |
| 635 | |
| 636 | m->type |= DRM_MODE_TYPE_DRIVER; |
| 637 | |
| 638 | drm_mode_probed_add(connector, m); |
| 639 | modes++; |
| 640 | } |
| 641 | |
| 642 | mode++; |
| 643 | } |
| 644 | |
| 645 | return modes; |
| 646 | } |
| 647 | |
Ben Skeggs | 6322175 | 2011-10-17 10:24:49 +1000 | [diff] [blame] | 648 | static void |
| 649 | nouveau_connector_detect_depth(struct drm_connector *connector) |
| 650 | { |
| 651 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 652 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 653 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
| 654 | struct nvbios *bios = &dev_priv->vbios; |
| 655 | struct drm_display_mode *mode = nv_connector->native_mode; |
| 656 | bool duallink; |
| 657 | |
| 658 | /* if the edid is feeling nice enough to provide this info, use it */ |
| 659 | if (nv_connector->edid && connector->display_info.bpc) |
| 660 | return; |
| 661 | |
| 662 | /* if not, we're out of options unless we're LVDS, default to 6bpc */ |
| 663 | connector->display_info.bpc = 6; |
| 664 | if (nv_encoder->dcb->type != OUTPUT_LVDS) |
| 665 | return; |
| 666 | |
| 667 | /* LVDS: panel straps */ |
| 668 | if (bios->fp_no_ddc) { |
| 669 | if (bios->fp.if_is_24bit) |
| 670 | connector->display_info.bpc = 8; |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | /* LVDS: DDC panel, need to first determine the number of links to |
| 675 | * know which if_is_24bit flag to check... |
| 676 | */ |
| 677 | if (nv_connector->edid && |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 678 | nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) |
Ben Skeggs | 6322175 | 2011-10-17 10:24:49 +1000 | [diff] [blame] | 679 | duallink = ((u8 *)nv_connector->edid)[121] == 2; |
| 680 | else |
| 681 | duallink = mode->clock >= bios->fp.duallink_transition_clk; |
| 682 | |
| 683 | if ((!duallink && (bios->fp.strapless_is_24bit & 1)) || |
| 684 | ( duallink && (bios->fp.strapless_is_24bit & 2))) |
| 685 | connector->display_info.bpc = 8; |
| 686 | } |
| 687 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 688 | static int |
| 689 | nouveau_connector_get_modes(struct drm_connector *connector) |
| 690 | { |
| 691 | struct drm_device *dev = connector->dev; |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 692 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 693 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 694 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 695 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 696 | int ret = 0; |
| 697 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 698 | /* destroy the native mode, the attached monitor could have changed. |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 699 | */ |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 700 | if (nv_connector->native_mode) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 701 | drm_mode_destroy(dev, nv_connector->native_mode); |
| 702 | nv_connector->native_mode = NULL; |
| 703 | } |
| 704 | |
| 705 | if (nv_connector->edid) |
| 706 | ret = drm_add_edid_modes(connector, nv_connector->edid); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 707 | else |
| 708 | if (nv_encoder->dcb->type == OUTPUT_LVDS && |
| 709 | (nv_encoder->dcb->lvdsconf.use_straps_for_mode || |
Francisco Jerez | 6e86e04 | 2010-07-03 18:36:39 +0200 | [diff] [blame] | 710 | dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) { |
Ben Skeggs | 80dad86 | 2010-09-23 16:37:39 +1000 | [diff] [blame] | 711 | struct drm_display_mode mode; |
| 712 | |
| 713 | nouveau_bios_fp_mode(dev, &mode); |
| 714 | nv_connector->native_mode = drm_mode_duplicate(dev, &mode); |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 715 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 716 | |
| 717 | /* Find the native mode if this is a digital panel, if we didn't |
| 718 | * find any modes through DDC previously add the native mode to |
| 719 | * the list of modes. |
| 720 | */ |
| 721 | if (!nv_connector->native_mode) |
| 722 | nv_connector->native_mode = |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 723 | nouveau_connector_native_mode(connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 724 | if (ret == 0 && nv_connector->native_mode) { |
| 725 | struct drm_display_mode *mode; |
| 726 | |
| 727 | mode = drm_mode_duplicate(dev, nv_connector->native_mode); |
| 728 | drm_mode_probed_add(connector, mode); |
| 729 | ret = 1; |
| 730 | } |
| 731 | |
Ben Skeggs | 6322175 | 2011-10-17 10:24:49 +1000 | [diff] [blame] | 732 | /* Attempt to determine display colour depth, this has to happen after |
| 733 | * we've determined the "native" mode for LVDS, as the VBIOS tables |
| 734 | * require us to compare against a pixel clock in some cases.. |
| 735 | */ |
| 736 | nouveau_connector_detect_depth(connector); |
| 737 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 738 | if (nv_encoder->dcb->type == OUTPUT_TV) |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 739 | ret = get_slave_funcs(encoder)->get_modes(encoder, connector); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 740 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 741 | if (nv_connector->type == DCB_CONNECTOR_LVDS || |
| 742 | nv_connector->type == DCB_CONNECTOR_LVDS_SPWG || |
| 743 | nv_connector->type == DCB_CONNECTOR_eDP) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 744 | ret += nouveau_connector_scaler_modes_add(connector); |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
Francisco Jerez | 1f5bd44 | 2010-10-02 16:00:35 +0200 | [diff] [blame] | 749 | static unsigned |
| 750 | get_tmds_link_bandwidth(struct drm_connector *connector) |
| 751 | { |
| 752 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 753 | struct drm_nouveau_private *dev_priv = connector->dev->dev_private; |
| 754 | struct dcb_entry *dcb = nv_connector->detected_encoder->dcb; |
| 755 | |
| 756 | if (dcb->location != DCB_LOC_ON_CHIP || |
| 757 | dev_priv->chipset >= 0x46) |
| 758 | return 165000; |
| 759 | else if (dev_priv->chipset >= 0x40) |
| 760 | return 155000; |
| 761 | else if (dev_priv->chipset >= 0x18) |
| 762 | return 135000; |
| 763 | else |
| 764 | return 112000; |
| 765 | } |
| 766 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 767 | static int |
| 768 | nouveau_connector_mode_valid(struct drm_connector *connector, |
| 769 | struct drm_display_mode *mode) |
| 770 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 771 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 772 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 773 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 774 | unsigned min_clock = 25000, max_clock = min_clock; |
| 775 | unsigned clock = mode->clock; |
| 776 | |
| 777 | switch (nv_encoder->dcb->type) { |
| 778 | case OUTPUT_LVDS: |
Ben Skeggs | 26099a7 | 2010-05-28 10:13:16 +1000 | [diff] [blame] | 779 | if (nv_connector->native_mode && |
| 780 | (mode->hdisplay > nv_connector->native_mode->hdisplay || |
| 781 | mode->vdisplay > nv_connector->native_mode->vdisplay)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 782 | return MODE_PANEL; |
| 783 | |
| 784 | min_clock = 0; |
| 785 | max_clock = 400000; |
| 786 | break; |
| 787 | case OUTPUT_TMDS: |
Francisco Jerez | 1f5bd44 | 2010-10-02 16:00:35 +0200 | [diff] [blame] | 788 | max_clock = get_tmds_link_bandwidth(connector); |
| 789 | if (nouveau_duallink && nv_encoder->dcb->duallink_possible) |
| 790 | max_clock *= 2; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 791 | break; |
| 792 | case OUTPUT_ANALOG: |
| 793 | max_clock = nv_encoder->dcb->crtconf.maxfreq; |
| 794 | if (!max_clock) |
| 795 | max_clock = 350000; |
| 796 | break; |
| 797 | case OUTPUT_TV: |
Francisco Jerez | 4a9f822 | 2010-07-20 16:48:08 +0200 | [diff] [blame] | 798 | return get_slave_funcs(encoder)->mode_valid(encoder, mode); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 799 | case OUTPUT_DP: |
Ben Skeggs | 75a1fcc | 2011-08-04 09:55:44 +1000 | [diff] [blame] | 800 | max_clock = nv_encoder->dp.link_nr; |
| 801 | max_clock *= nv_encoder->dp.link_bw; |
Adam Jackson | 5c79507 | 2011-10-25 13:09:43 -0400 | [diff] [blame] | 802 | clock = clock * nouveau_connector_bpp(connector) / 10; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 803 | break; |
Ben Skeggs | e7cc51c | 2010-02-24 10:31:39 +1000 | [diff] [blame] | 804 | default: |
| 805 | BUG_ON(1); |
| 806 | return MODE_BAD; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | if (clock < min_clock) |
| 810 | return MODE_CLOCK_LOW; |
| 811 | |
| 812 | if (clock > max_clock) |
| 813 | return MODE_CLOCK_HIGH; |
| 814 | |
| 815 | return MODE_OK; |
| 816 | } |
| 817 | |
| 818 | static struct drm_encoder * |
| 819 | nouveau_connector_best_encoder(struct drm_connector *connector) |
| 820 | { |
| 821 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
| 822 | |
| 823 | if (nv_connector->detected_encoder) |
| 824 | return to_drm_encoder(nv_connector->detected_encoder); |
| 825 | |
| 826 | return NULL; |
| 827 | } |
| 828 | |
| 829 | static const struct drm_connector_helper_funcs |
| 830 | nouveau_connector_helper_funcs = { |
| 831 | .get_modes = nouveau_connector_get_modes, |
| 832 | .mode_valid = nouveau_connector_mode_valid, |
| 833 | .best_encoder = nouveau_connector_best_encoder, |
| 834 | }; |
| 835 | |
| 836 | static const struct drm_connector_funcs |
| 837 | nouveau_connector_funcs = { |
| 838 | .dpms = drm_helper_connector_dpms, |
| 839 | .save = NULL, |
| 840 | .restore = NULL, |
| 841 | .detect = nouveau_connector_detect, |
| 842 | .destroy = nouveau_connector_destroy, |
| 843 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 844 | .set_property = nouveau_connector_set_property, |
| 845 | .force = nouveau_connector_force |
| 846 | }; |
| 847 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 848 | static const struct drm_connector_funcs |
| 849 | nouveau_connector_funcs_lvds = { |
| 850 | .dpms = drm_helper_connector_dpms, |
| 851 | .save = NULL, |
| 852 | .restore = NULL, |
| 853 | .detect = nouveau_connector_detect_lvds, |
| 854 | .destroy = nouveau_connector_destroy, |
| 855 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 856 | .set_property = nouveau_connector_set_property, |
| 857 | .force = nouveau_connector_force |
| 858 | }; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 859 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 860 | static int |
| 861 | drm_conntype_from_dcb(enum dcb_connector_type dcb) |
| 862 | { |
| 863 | switch (dcb) { |
| 864 | case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA; |
| 865 | case DCB_CONNECTOR_TV_0 : |
| 866 | case DCB_CONNECTOR_TV_1 : |
| 867 | case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV; |
| 868 | case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII; |
| 869 | case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID; |
| 870 | case DCB_CONNECTOR_LVDS : |
| 871 | case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS; |
| 872 | case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort; |
| 873 | case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP; |
| 874 | case DCB_CONNECTOR_HDMI_0 : |
| 875 | case DCB_CONNECTOR_HDMI_1 : return DRM_MODE_CONNECTOR_HDMIA; |
| 876 | default: |
| 877 | break; |
| 878 | } |
| 879 | |
| 880 | return DRM_MODE_CONNECTOR_Unknown; |
| 881 | } |
| 882 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 883 | struct drm_connector * |
| 884 | nouveau_connector_create(struct drm_device *dev, int index) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 885 | { |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 886 | const struct drm_connector_funcs *funcs = &nouveau_connector_funcs; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 887 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 888 | struct nouveau_display_engine *disp = &dev_priv->engine.display; |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 889 | struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 890 | struct nouveau_connector *nv_connector = NULL; |
| 891 | struct drm_connector *connector; |
Francisco Jerez | 2fa67f1 | 2010-06-16 15:52:44 +0200 | [diff] [blame] | 892 | int type, ret = 0; |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 893 | bool dummy; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 894 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 895 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 896 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 897 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 898 | nv_connector = nouveau_connector(connector); |
| 899 | if (nv_connector->index == index) |
| 900 | return connector; |
Ben Skeggs | 7f612d8 | 2010-02-24 12:07:31 +1000 | [diff] [blame] | 901 | } |
| 902 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 903 | nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL); |
| 904 | if (!nv_connector) |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 905 | return ERR_PTR(-ENOMEM); |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 906 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 907 | connector = &nv_connector->base; |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 908 | nv_connector->index = index; |
| 909 | |
| 910 | /* attempt to parse vbios connector type and hotplug gpio */ |
| 911 | nv_connector->dcb = dcb_conn(dev, index); |
| 912 | if (nv_connector->dcb) { |
| 913 | static const u8 hpd[16] = { |
| 914 | 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff, |
| 915 | 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60, |
| 916 | }; |
| 917 | |
| 918 | u32 entry = ROM16(nv_connector->dcb[0]); |
| 919 | if (dcb_conntab(dev)[3] >= 4) |
| 920 | entry |= (u32)ROM16(nv_connector->dcb[2]) << 16; |
| 921 | |
| 922 | nv_connector->hpd = ffs((entry & 0x07033000) >> 12); |
| 923 | nv_connector->hpd = hpd[nv_connector->hpd]; |
| 924 | |
| 925 | nv_connector->type = nv_connector->dcb[0]; |
| 926 | if (drm_conntype_from_dcb(nv_connector->type) == |
| 927 | DRM_MODE_CONNECTOR_Unknown) { |
| 928 | NV_WARN(dev, "unknown connector type %02x\n", |
| 929 | nv_connector->type); |
| 930 | nv_connector->type = DCB_CONNECTOR_NONE; |
| 931 | } |
| 932 | |
| 933 | /* Gigabyte NX85T */ |
| 934 | if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) { |
| 935 | if (nv_connector->type == DCB_CONNECTOR_HDMI_1) |
| 936 | nv_connector->type = DCB_CONNECTOR_DVI_I; |
| 937 | } |
| 938 | |
| 939 | /* Gigabyte GV-NX86T512H */ |
| 940 | if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) { |
| 941 | if (nv_connector->type == DCB_CONNECTOR_HDMI_1) |
| 942 | nv_connector->type = DCB_CONNECTOR_DVI_I; |
| 943 | } |
| 944 | } else { |
| 945 | nv_connector->type = DCB_CONNECTOR_NONE; |
| 946 | nv_connector->hpd = DCB_GPIO_UNUSED; |
| 947 | } |
| 948 | |
| 949 | /* no vbios data, or an unknown dcb connector type - attempt to |
| 950 | * figure out something suitable ourselves |
| 951 | */ |
| 952 | if (nv_connector->type == DCB_CONNECTOR_NONE) { |
| 953 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 954 | struct dcb_table *dcbt = &dev_priv->vbios.dcb; |
| 955 | u32 encoders = 0; |
| 956 | int i; |
| 957 | |
| 958 | for (i = 0; i < dcbt->entries; i++) { |
| 959 | if (dcbt->entry[i].connector == nv_connector->index) |
| 960 | encoders |= (1 << dcbt->entry[i].type); |
| 961 | } |
| 962 | |
| 963 | if (encoders & (1 << OUTPUT_DP)) { |
| 964 | if (encoders & (1 << OUTPUT_TMDS)) |
| 965 | nv_connector->type = DCB_CONNECTOR_DP; |
| 966 | else |
| 967 | nv_connector->type = DCB_CONNECTOR_eDP; |
| 968 | } else |
| 969 | if (encoders & (1 << OUTPUT_TMDS)) { |
| 970 | if (encoders & (1 << OUTPUT_ANALOG)) |
| 971 | nv_connector->type = DCB_CONNECTOR_DVI_I; |
| 972 | else |
| 973 | nv_connector->type = DCB_CONNECTOR_DVI_D; |
| 974 | } else |
| 975 | if (encoders & (1 << OUTPUT_ANALOG)) { |
| 976 | nv_connector->type = DCB_CONNECTOR_VGA; |
| 977 | } else |
| 978 | if (encoders & (1 << OUTPUT_LVDS)) { |
| 979 | nv_connector->type = DCB_CONNECTOR_LVDS; |
| 980 | } else |
| 981 | if (encoders & (1 << OUTPUT_TV)) { |
| 982 | nv_connector->type = DCB_CONNECTOR_TV_0; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | type = drm_conntype_from_dcb(nv_connector->type); |
| 987 | if (type == DRM_MODE_CONNECTOR_LVDS) { |
| 988 | ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy); |
| 989 | if (ret) { |
| 990 | NV_ERROR(dev, "Error parsing LVDS table, disabling\n"); |
| 991 | kfree(nv_connector); |
| 992 | return ERR_PTR(ret); |
| 993 | } |
| 994 | |
| 995 | funcs = &nouveau_connector_funcs_lvds; |
| 996 | } else { |
| 997 | funcs = &nouveau_connector_funcs; |
| 998 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 999 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1000 | /* defaults, will get overridden in detect() */ |
| 1001 | connector->interlace_allowed = false; |
| 1002 | connector->doublescan_allowed = false; |
| 1003 | |
Ben Skeggs | d17f395 | 2010-06-01 13:32:42 +1000 | [diff] [blame] | 1004 | drm_connector_init(dev, connector, funcs, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1005 | drm_connector_helper_add(connector, &nouveau_connector_helper_funcs); |
| 1006 | |
| 1007 | /* Init DVI-I specific properties */ |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1008 | if (nv_connector->type == DCB_CONNECTOR_DVI_I) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1009 | drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1010 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 1011 | /* Add overscan compensation options to digital outputs */ |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 1012 | if (disp->underscan_property && |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1013 | (nv_connector->type == DCB_CONNECTOR_DVI_D || |
| 1014 | nv_connector->type == DCB_CONNECTOR_DVI_I || |
| 1015 | nv_connector->type == DCB_CONNECTOR_HDMI_0 || |
| 1016 | nv_connector->type == DCB_CONNECTOR_HDMI_1 || |
| 1017 | nv_connector->type == DCB_CONNECTOR_DP)) { |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 1018 | drm_connector_attach_property(connector, |
| 1019 | disp->underscan_property, |
| 1020 | UNDERSCAN_OFF); |
| 1021 | drm_connector_attach_property(connector, |
| 1022 | disp->underscan_hborder_property, |
| 1023 | 0); |
| 1024 | drm_connector_attach_property(connector, |
| 1025 | disp->underscan_vborder_property, |
| 1026 | 0); |
| 1027 | } |
| 1028 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1029 | switch (nv_connector->type) { |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 1030 | case DCB_CONNECTOR_VGA: |
| 1031 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1032 | drm_connector_attach_property(connector, |
| 1033 | dev->mode_config.scaling_mode_property, |
| 1034 | nv_connector->scaling_mode); |
| 1035 | } |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 1036 | /* fall-through */ |
| 1037 | case DCB_CONNECTOR_TV_0: |
| 1038 | case DCB_CONNECTOR_TV_1: |
| 1039 | case DCB_CONNECTOR_TV_3: |
| 1040 | nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; |
| 1041 | break; |
| 1042 | default: |
| 1043 | nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; |
| 1044 | |
| 1045 | drm_connector_attach_property(connector, |
| 1046 | dev->mode_config.scaling_mode_property, |
| 1047 | nv_connector->scaling_mode); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 1048 | if (disp->dithering_mode) { |
| 1049 | nv_connector->dithering_mode = DITHERING_MODE_AUTO; |
| 1050 | drm_connector_attach_property(connector, |
| 1051 | disp->dithering_mode, |
| 1052 | nv_connector->dithering_mode); |
| 1053 | } |
| 1054 | if (disp->dithering_depth) { |
| 1055 | nv_connector->dithering_depth = DITHERING_DEPTH_AUTO; |
| 1056 | drm_connector_attach_property(connector, |
| 1057 | disp->dithering_depth, |
| 1058 | nv_connector->dithering_depth); |
| 1059 | } |
Ben Skeggs | be079e9 | 2010-02-24 14:01:40 +1000 | [diff] [blame] | 1060 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1061 | } |
| 1062 | |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1063 | if (nv_connector->hpd != DCB_GPIO_UNUSED && pgpio->irq_register) { |
| 1064 | pgpio->irq_register(dev, nv_connector->hpd, |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 1065 | nouveau_connector_hotplug, connector); |
Ben Skeggs | 1cb70b3 | 2011-07-13 16:15:57 +1000 | [diff] [blame] | 1066 | |
| 1067 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 1068 | } else { |
| 1069 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 1070 | } |
| 1071 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1072 | drm_sysfs_connector_add(connector); |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1073 | return connector; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1074 | } |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 1075 | |
| 1076 | static void |
| 1077 | nouveau_connector_hotplug(void *data, int plugged) |
| 1078 | { |
| 1079 | struct drm_connector *connector = data; |
| 1080 | struct drm_device *dev = connector->dev; |
| 1081 | |
Ben Skeggs | 68c9918 | 2011-08-02 13:57:10 +1000 | [diff] [blame] | 1082 | NV_DEBUG(dev, "%splugged %s\n", plugged ? "" : "un", |
| 1083 | drm_get_connector_name(connector)); |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 1084 | |
Ben Skeggs | 68c9918 | 2011-08-02 13:57:10 +1000 | [diff] [blame] | 1085 | if (plugged) |
| 1086 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); |
| 1087 | else |
| 1088 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
Ben Skeggs | fce2bad | 2010-11-11 16:14:56 +1000 | [diff] [blame] | 1089 | |
| 1090 | drm_helper_hpd_irq_event(dev); |
| 1091 | } |