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