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