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