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