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