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