Commit | Line | Data |
---|---|---|
6ee73861 BS |
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 | ||
a1470890 BS |
27 | #include <acpi/button.h> |
28 | ||
5addcf0a DA |
29 | #include <linux/pm_runtime.h> |
30 | ||
760285e7 DH |
31 | #include <drm/drmP.h> |
32 | #include <drm/drm_edid.h> | |
33 | #include <drm/drm_crtc_helper.h> | |
a1470890 | 34 | |
6ee73861 | 35 | #include "nouveau_reg.h" |
77145f1c | 36 | #include "nouveau_drm.h" |
1a646342 | 37 | #include "dispnv04/hw.h" |
c0077061 | 38 | #include "nouveau_acpi.h" |
6ee73861 | 39 | |
77145f1c BS |
40 | #include "nouveau_display.h" |
41 | #include "nouveau_connector.h" | |
6ee73861 BS |
42 | #include "nouveau_encoder.h" |
43 | #include "nouveau_crtc.h" | |
77145f1c | 44 | |
923bc416 | 45 | #include <nvif/class.h> |
7568b106 | 46 | #include <nvif/cl0046.h> |
79ca2770 BS |
47 | #include <nvif/event.h> |
48 | ||
77145f1c | 49 | MODULE_PARM_DESC(tv_disable, "Disable TV-out detection"); |
703fa264 | 50 | int nouveau_tv_disable = 0; |
77145f1c BS |
51 | module_param_named(tv_disable, nouveau_tv_disable, int, 0400); |
52 | ||
53 | MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status"); | |
703fa264 | 54 | int nouveau_ignorelid = 0; |
77145f1c BS |
55 | module_param_named(ignorelid, nouveau_ignorelid, int, 0400); |
56 | ||
57 | MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (default: enabled)"); | |
703fa264 | 58 | int nouveau_duallink = 1; |
77145f1c | 59 | module_param_named(duallink, nouveau_duallink, int, 0400); |
6ee73861 | 60 | |
1a0c96c0 IM |
61 | MODULE_PARM_DESC(hdmimhz, "Force a maximum HDMI pixel clock (in MHz)"); |
62 | int nouveau_hdmimhz = 0; | |
63 | module_param_named(hdmimhz, nouveau_hdmimhz, int, 0400); | |
64 | ||
10b461e4 | 65 | struct nouveau_encoder * |
e19b20bb | 66 | find_encoder(struct drm_connector *connector, int type) |
6ee73861 BS |
67 | { |
68 | struct drm_device *dev = connector->dev; | |
69 | struct nouveau_encoder *nv_encoder; | |
6d385c0a | 70 | struct drm_encoder *enc; |
6ee73861 BS |
71 | int i, id; |
72 | ||
73 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { | |
74 | id = connector->encoder_ids[i]; | |
75 | if (!id) | |
76 | break; | |
77 | ||
6d385c0a RC |
78 | enc = drm_encoder_find(dev, id); |
79 | if (!enc) | |
6ee73861 | 80 | continue; |
6d385c0a | 81 | nv_encoder = nouveau_encoder(enc); |
6ee73861 | 82 | |
4874322e BS |
83 | if (type == DCB_OUTPUT_ANY || |
84 | (nv_encoder->dcb && nv_encoder->dcb->type == type)) | |
6ee73861 BS |
85 | return nv_encoder; |
86 | } | |
87 | ||
88 | return NULL; | |
89 | } | |
90 | ||
91 | struct nouveau_connector * | |
92 | nouveau_encoder_connector_get(struct nouveau_encoder *encoder) | |
93 | { | |
94 | struct drm_device *dev = to_drm_encoder(encoder)->dev; | |
95 | struct drm_connector *drm_connector; | |
96 | ||
97 | list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { | |
98 | if (drm_connector->encoder == to_drm_encoder(encoder)) | |
99 | return nouveau_connector(drm_connector); | |
100 | } | |
101 | ||
102 | return NULL; | |
103 | } | |
104 | ||
6ee73861 | 105 | static void |
fce2bad0 | 106 | nouveau_connector_destroy(struct drm_connector *connector) |
6ee73861 | 107 | { |
fce2bad0 | 108 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
80bc340b | 109 | nvif_notify_fini(&nv_connector->hpd); |
c8ebe275 | 110 | kfree(nv_connector->edid); |
34ea3d38 | 111 | drm_connector_unregister(connector); |
fce2bad0 | 112 | drm_connector_cleanup(connector); |
8894f491 BS |
113 | if (nv_connector->aux.transfer) |
114 | drm_dp_aux_unregister(&nv_connector->aux); | |
fce2bad0 | 115 | kfree(connector); |
6ee73861 BS |
116 | } |
117 | ||
8777c5c1 BS |
118 | static struct nouveau_encoder * |
119 | nouveau_connector_ddc_detect(struct drm_connector *connector) | |
6ee73861 BS |
120 | { |
121 | struct drm_device *dev = connector->dev; | |
1a1841d3 | 122 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
77145f1c | 123 | struct nouveau_drm *drm = nouveau_drm(dev); |
be83cd4e | 124 | struct nvkm_gpio *gpio = nvxx_gpio(&drm->device); |
8777c5c1 | 125 | struct nouveau_encoder *nv_encoder; |
6d385c0a | 126 | struct drm_encoder *encoder; |
1a1841d3 BS |
127 | int i, panel = -ENODEV; |
128 | ||
129 | /* eDP panels need powering on by us (if the VBIOS doesn't default it | |
130 | * to on) before doing any AUX channel transactions. LVDS panel power | |
131 | * is handled by the SOR itself, and not required for LVDS DDC. | |
132 | */ | |
133 | if (nv_connector->type == DCB_CONNECTOR_eDP) { | |
2ea7249f | 134 | panel = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff); |
1a1841d3 | 135 | if (panel == 0) { |
2ea7249f | 136 | nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1); |
1a1841d3 BS |
137 | msleep(300); |
138 | } | |
139 | } | |
6ee73861 | 140 | |
8777c5c1 BS |
141 | for (i = 0; nv_encoder = NULL, i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
142 | int id = connector->encoder_ids[i]; | |
143 | if (id == 0) | |
6ee73861 BS |
144 | break; |
145 | ||
6d385c0a RC |
146 | encoder = drm_encoder_find(dev, id); |
147 | if (!encoder) | |
6ee73861 | 148 | continue; |
6d385c0a | 149 | nv_encoder = nouveau_encoder(encoder); |
4ca2b712 | 150 | |
8777c5c1 BS |
151 | if (nv_encoder->dcb->type == DCB_OUTPUT_DP) { |
152 | int ret = nouveau_dp_detect(nv_encoder); | |
153 | if (ret == 0) | |
154 | break; | |
155 | } else | |
156 | if (nv_encoder->i2c) { | |
2aa5eac5 | 157 | if (nvkm_probe_i2c(nv_encoder->i2c, 0x50)) |
8777c5c1 | 158 | break; |
6ee73861 BS |
159 | } |
160 | } | |
161 | ||
1a1841d3 BS |
162 | /* eDP panel not detected, restore panel power GPIO to previous |
163 | * state to avoid confusing the SOR for other output types. | |
164 | */ | |
8777c5c1 | 165 | if (!nv_encoder && panel == 0) |
2ea7249f | 166 | nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel); |
1a1841d3 | 167 | |
8777c5c1 | 168 | return nv_encoder; |
6ee73861 BS |
169 | } |
170 | ||
c16c5707 FJ |
171 | static struct nouveau_encoder * |
172 | nouveau_connector_of_detect(struct drm_connector *connector) | |
173 | { | |
174 | #ifdef __powerpc__ | |
175 | struct drm_device *dev = connector->dev; | |
176 | struct nouveau_connector *nv_connector = nouveau_connector(connector); | |
177 | struct nouveau_encoder *nv_encoder; | |
178 | struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev); | |
179 | ||
180 | if (!dn || | |
cb75d97e BS |
181 | !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) || |
182 | (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG)))) | |
c16c5707 FJ |
183 | return NULL; |
184 | ||
185 | for_each_child_of_node(dn, cn) { | |
186 | const char *name = of_get_property(cn, "name", NULL); | |
187 | const void *edid = of_get_property(cn, "EDID", NULL); | |
188 | int idx = name ? name[strlen(name) - 1] - 'A' : 0; | |
189 | ||
190 | if (nv_encoder->dcb->i2c_index == idx && edid) { | |
191 | nv_connector->edid = | |
192 | kmemdup(edid, EDID_LENGTH, GFP_KERNEL); | |
193 | of_node_put(cn); | |
194 | return nv_encoder; | |
195 | } | |
196 | } | |
197 | #endif | |
198 | return NULL; | |
199 | } | |
200 | ||
6ee73861 BS |
201 | static void |
202 | nouveau_connector_set_encoder(struct drm_connector *connector, | |
203 | struct nouveau_encoder *nv_encoder) | |
204 | { | |
205 | struct nouveau_connector *nv_connector = nouveau_connector(connector); | |
77145f1c | 206 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
6ee73861 BS |
207 | struct drm_device *dev = connector->dev; |
208 | ||
209 | if (nv_connector->detected_encoder == nv_encoder) | |
210 | return; | |
211 | nv_connector->detected_encoder = nv_encoder; | |
212 | ||
967e7bde | 213 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { |
c8334423 BS |
214 | connector->interlace_allowed = true; |
215 | connector->doublescan_allowed = true; | |
216 | } else | |
cb75d97e BS |
217 | if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS || |
218 | nv_encoder->dcb->type == DCB_OUTPUT_TMDS) { | |
6ee73861 BS |
219 | connector->doublescan_allowed = false; |
220 | connector->interlace_allowed = false; | |
221 | } else { | |
222 | connector->doublescan_allowed = true; | |
967e7bde BS |
223 | if (drm->device.info.family == NV_DEVICE_INFO_V0_KELVIN || |
224 | (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS && | |
4a0ff754 IM |
225 | (dev->pdev->device & 0x0ff0) != 0x0100 && |
226 | (dev->pdev->device & 0x0ff0) != 0x0150)) | |
6ee73861 BS |
227 | /* HW is broken */ |
228 | connector->interlace_allowed = false; | |
229 | else | |
230 | connector->interlace_allowed = true; | |
231 | } | |
232 | ||
befb51e9 | 233 | if (nv_connector->type == DCB_CONNECTOR_DVI_I) { |
2db83827 | 234 | drm_object_property_set_value(&connector->base, |
6ee73861 | 235 | dev->mode_config.dvi_i_subconnector_property, |
cb75d97e | 236 | nv_encoder->dcb->type == DCB_OUTPUT_TMDS ? |
6ee73861 BS |
237 | DRM_MODE_SUBCONNECTOR_DVID : |
238 | DRM_MODE_SUBCONNECTOR_DVIA); | |
239 | } | |
240 | } | |
241 | ||
242 | static enum drm_connector_status | |
930a9e28 | 243 | nouveau_connector_detect(struct drm_connector *connector, bool force) |
6ee73861 BS |
244 | { |
245 | struct drm_device *dev = connector->dev; | |
77145f1c | 246 | struct nouveau_drm *drm = nouveau_drm(dev); |
6ee73861 BS |
247 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
248 | struct nouveau_encoder *nv_encoder = NULL; | |
e19b20bb | 249 | struct nouveau_encoder *nv_partner; |
2aa5eac5 | 250 | struct i2c_adapter *i2c; |
03cd06ca | 251 | int type; |
5addcf0a DA |
252 | int ret; |
253 | enum drm_connector_status conn_status = connector_status_disconnected; | |
6ee73861 | 254 | |
b8780e2a FJ |
255 | /* Cleanup the previous EDID block. */ |
256 | if (nv_connector->edid) { | |
257 | drm_mode_connector_update_edid_property(connector, NULL); | |
258 | kfree(nv_connector->edid); | |
259 | nv_connector->edid = NULL; | |
260 | } | |
c8ebe275 | 261 | |
5addcf0a | 262 | ret = pm_runtime_get_sync(connector->dev->dev); |
b6c4285a | 263 | if (ret < 0 && ret != -EACCES) |
5addcf0a DA |
264 | return conn_status; |
265 | ||
8777c5c1 BS |
266 | nv_encoder = nouveau_connector_ddc_detect(connector); |
267 | if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) { | |
2aa5eac5 | 268 | nv_connector->edid = drm_get_edid(connector, i2c); |
6ee73861 BS |
269 | drm_mode_connector_update_edid_property(connector, |
270 | nv_connector->edid); | |
271 | if (!nv_connector->edid) { | |
77145f1c | 272 | NV_ERROR(drm, "DDC responded, but no EDID for %s\n", |
8c6c361a | 273 | connector->name); |
0ed3165e | 274 | goto detect_analog; |
6ee73861 BS |
275 | } |
276 | ||
6ee73861 BS |
277 | /* Override encoder type for DVI-I based on whether EDID |
278 | * says the display is digital or analog, both use the | |
279 | * same i2c channel so the value returned from ddc_detect | |
280 | * isn't necessarily correct. | |
281 | */ | |
e19b20bb | 282 | nv_partner = NULL; |
cb75d97e BS |
283 | if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS) |
284 | nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG); | |
285 | if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG) | |
286 | nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS); | |
287 | ||
288 | if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG && | |
289 | nv_partner->dcb->type == DCB_OUTPUT_TMDS) || | |
290 | (nv_encoder->dcb->type == DCB_OUTPUT_TMDS && | |
291 | nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) { | |
6ee73861 | 292 | if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL) |
cb75d97e | 293 | type = DCB_OUTPUT_TMDS; |
6ee73861 | 294 | else |
cb75d97e | 295 | type = DCB_OUTPUT_ANALOG; |
6ee73861 | 296 | |
e19b20bb | 297 | nv_encoder = find_encoder(connector, type); |
6ee73861 BS |
298 | } |
299 | ||
300 | nouveau_connector_set_encoder(connector, nv_encoder); | |
5addcf0a DA |
301 | conn_status = connector_status_connected; |
302 | goto out; | |
6ee73861 BS |
303 | } |
304 | ||
c16c5707 FJ |
305 | nv_encoder = nouveau_connector_of_detect(connector); |
306 | if (nv_encoder) { | |
307 | nouveau_connector_set_encoder(connector, nv_encoder); | |
5addcf0a DA |
308 | conn_status = connector_status_connected; |
309 | goto out; | |
c16c5707 FJ |
310 | } |
311 | ||
0ed3165e | 312 | detect_analog: |
cb75d97e | 313 | nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG); |
f4053509 | 314 | if (!nv_encoder && !nouveau_tv_disable) |
cb75d97e | 315 | nv_encoder = find_encoder(connector, DCB_OUTPUT_TV); |
84b8081c | 316 | if (nv_encoder && force) { |
6ee73861 | 317 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
d58ded76 | 318 | const struct drm_encoder_helper_funcs *helper = |
6ee73861 BS |
319 | encoder->helper_private; |
320 | ||
321 | if (helper->detect(encoder, connector) == | |
322 | connector_status_connected) { | |
323 | nouveau_connector_set_encoder(connector, nv_encoder); | |
5addcf0a DA |
324 | conn_status = connector_status_connected; |
325 | goto out; | |
6ee73861 BS |
326 | } |
327 | ||
328 | } | |
329 | ||
5addcf0a DA |
330 | out: |
331 | ||
332 | pm_runtime_mark_last_busy(connector->dev->dev); | |
333 | pm_runtime_put_autosuspend(connector->dev->dev); | |
334 | ||
335 | return conn_status; | |
6ee73861 BS |
336 | } |
337 | ||
d17f395c | 338 | static enum drm_connector_status |
930a9e28 | 339 | nouveau_connector_detect_lvds(struct drm_connector *connector, bool force) |
d17f395c BS |
340 | { |
341 | struct drm_device *dev = connector->dev; | |
77145f1c | 342 | struct nouveau_drm *drm = nouveau_drm(dev); |
d17f395c BS |
343 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
344 | struct nouveau_encoder *nv_encoder = NULL; | |
345 | enum drm_connector_status status = connector_status_disconnected; | |
346 | ||
347 | /* Cleanup the previous EDID block. */ | |
348 | if (nv_connector->edid) { | |
349 | drm_mode_connector_update_edid_property(connector, NULL); | |
350 | kfree(nv_connector->edid); | |
351 | nv_connector->edid = NULL; | |
352 | } | |
353 | ||
cb75d97e | 354 | nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS); |
d17f395c BS |
355 | if (!nv_encoder) |
356 | return connector_status_disconnected; | |
357 | ||
a6ed76d7 | 358 | /* Try retrieving EDID via DDC */ |
77145f1c | 359 | if (!drm->vbios.fp_no_ddc) { |
930a9e28 | 360 | status = nouveau_connector_detect(connector, force); |
d17f395c BS |
361 | if (status == connector_status_connected) |
362 | goto out; | |
363 | } | |
364 | ||
a6ed76d7 BS |
365 | /* On some laptops (Sony, i'm looking at you) there appears to |
366 | * be no direct way of accessing the panel's EDID. The only | |
367 | * option available to us appears to be to ask ACPI for help.. | |
368 | * | |
369 | * It's important this check's before trying straps, one of the | |
370 | * said manufacturer's laptops are configured in such a way | |
371 | * the nouveau decides an entry in the VBIOS FP mode table is | |
372 | * valid - it's not (rh#613284) | |
373 | */ | |
374 | if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) { | |
df285500 | 375 | if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) { |
a6ed76d7 BS |
376 | status = connector_status_connected; |
377 | goto out; | |
378 | } | |
379 | } | |
380 | ||
d17f395c BS |
381 | /* If no EDID found above, and the VBIOS indicates a hardcoded |
382 | * modeline is avalilable for the panel, set it as the panel's | |
383 | * native mode and exit. | |
384 | */ | |
77145f1c | 385 | if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc || |
d17f395c BS |
386 | nv_encoder->dcb->lvdsconf.use_straps_for_mode)) { |
387 | status = connector_status_connected; | |
388 | goto out; | |
389 | } | |
390 | ||
391 | /* Still nothing, some VBIOS images have a hardcoded EDID block | |
392 | * stored for the panel stored in them. | |
393 | */ | |
77145f1c | 394 | if (!drm->vbios.fp_no_ddc) { |
d17f395c BS |
395 | struct edid *edid = |
396 | (struct edid *)nouveau_bios_embedded_edid(dev); | |
397 | if (edid) { | |
a441dbb1 MS |
398 | nv_connector->edid = |
399 | kmemdup(edid, EDID_LENGTH, GFP_KERNEL); | |
400 | if (nv_connector->edid) | |
401 | status = connector_status_connected; | |
d17f395c BS |
402 | } |
403 | } | |
404 | ||
405 | out: | |
406 | #if defined(CONFIG_ACPI_BUTTON) || \ | |
407 | (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE)) | |
408 | if (status == connector_status_connected && | |
409 | !nouveau_ignorelid && !acpi_lid_open()) | |
410 | status = connector_status_unknown; | |
411 | #endif | |
412 | ||
413 | drm_mode_connector_update_edid_property(connector, nv_connector->edid); | |
3195c5f9 | 414 | nouveau_connector_set_encoder(connector, nv_encoder); |
d17f395c BS |
415 | return status; |
416 | } | |
417 | ||
6ee73861 BS |
418 | static void |
419 | nouveau_connector_force(struct drm_connector *connector) | |
420 | { | |
77145f1c | 421 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
be079e97 | 422 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
6ee73861 BS |
423 | struct nouveau_encoder *nv_encoder; |
424 | int type; | |
425 | ||
befb51e9 | 426 | if (nv_connector->type == DCB_CONNECTOR_DVI_I) { |
6ee73861 | 427 | if (connector->force == DRM_FORCE_ON_DIGITAL) |
cb75d97e | 428 | type = DCB_OUTPUT_TMDS; |
6ee73861 | 429 | else |
cb75d97e | 430 | type = DCB_OUTPUT_ANALOG; |
6ee73861 | 431 | } else |
cb75d97e | 432 | type = DCB_OUTPUT_ANY; |
6ee73861 | 433 | |
e19b20bb | 434 | nv_encoder = find_encoder(connector, type); |
6ee73861 | 435 | if (!nv_encoder) { |
77145f1c | 436 | NV_ERROR(drm, "can't find encoder to force %s on!\n", |
8c6c361a | 437 | connector->name); |
6ee73861 BS |
438 | connector->status = connector_status_disconnected; |
439 | return; | |
440 | } | |
441 | ||
442 | nouveau_connector_set_encoder(connector, nv_encoder); | |
443 | } | |
444 | ||
445 | static int | |
446 | nouveau_connector_set_property(struct drm_connector *connector, | |
447 | struct drm_property *property, uint64_t value) | |
448 | { | |
77145f1c | 449 | struct nouveau_display *disp = nouveau_display(connector->dev); |
6ee73861 BS |
450 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
451 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; | |
4a9f822f | 452 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
6ee73861 | 453 | struct drm_device *dev = connector->dev; |
b29caa58 | 454 | struct nouveau_crtc *nv_crtc; |
6ee73861 BS |
455 | int ret; |
456 | ||
b29caa58 BS |
457 | nv_crtc = NULL; |
458 | if (connector->encoder && connector->encoder->crtc) | |
459 | nv_crtc = nouveau_crtc(connector->encoder->crtc); | |
460 | ||
6ee73861 BS |
461 | /* Scaling mode */ |
462 | if (property == dev->mode_config.scaling_mode_property) { | |
6ee73861 BS |
463 | bool modeset = false; |
464 | ||
465 | switch (value) { | |
466 | case DRM_MODE_SCALE_NONE: | |
576f7911 BS |
467 | /* We allow 'None' for EDID modes, even on a fixed |
468 | * panel (some exist with support for lower refresh | |
469 | * rates, which people might want to use for power | |
470 | * saving purposes). | |
471 | * | |
472 | * Non-EDID modes will force the use of GPU scaling | |
473 | * to the native mode regardless of this setting. | |
474 | */ | |
475 | switch (nv_connector->type) { | |
476 | case DCB_CONNECTOR_LVDS: | |
477 | case DCB_CONNECTOR_LVDS_SPWG: | |
478 | case DCB_CONNECTOR_eDP: | |
479 | /* ... except prior to G80, where the code | |
480 | * doesn't support such things. | |
481 | */ | |
482 | if (disp->disp.oclass < NV50_DISP) | |
483 | return -EINVAL; | |
484 | break; | |
485 | default: | |
486 | break; | |
487 | } | |
488 | break; | |
6ee73861 BS |
489 | case DRM_MODE_SCALE_FULLSCREEN: |
490 | case DRM_MODE_SCALE_CENTER: | |
491 | case DRM_MODE_SCALE_ASPECT: | |
492 | break; | |
493 | default: | |
494 | return -EINVAL; | |
495 | } | |
496 | ||
6ee73861 BS |
497 | /* Changing between GPU and panel scaling requires a full |
498 | * modeset | |
499 | */ | |
500 | if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) || | |
501 | (value == DRM_MODE_SCALE_NONE)) | |
502 | modeset = true; | |
503 | nv_connector->scaling_mode = value; | |
504 | ||
6ee73861 BS |
505 | if (!nv_crtc) |
506 | return 0; | |
507 | ||
508 | if (modeset || !nv_crtc->set_scale) { | |
509 | ret = drm_crtc_helper_set_mode(&nv_crtc->base, | |
510 | &nv_crtc->base.mode, | |
511 | nv_crtc->base.x, | |
512 | nv_crtc->base.y, NULL); | |
513 | if (!ret) | |
514 | return -EINVAL; | |
515 | } else { | |
488ff207 | 516 | ret = nv_crtc->set_scale(nv_crtc, true); |
6ee73861 BS |
517 | if (ret) |
518 | return ret; | |
519 | } | |
520 | ||
521 | return 0; | |
522 | } | |
523 | ||
b29caa58 BS |
524 | /* Underscan */ |
525 | if (property == disp->underscan_property) { | |
526 | if (nv_connector->underscan != value) { | |
527 | nv_connector->underscan = value; | |
528 | if (!nv_crtc || !nv_crtc->set_scale) | |
529 | return 0; | |
530 | ||
488ff207 | 531 | return nv_crtc->set_scale(nv_crtc, true); |
b29caa58 BS |
532 | } |
533 | ||
534 | return 0; | |
535 | } | |
536 | ||
537 | if (property == disp->underscan_hborder_property) { | |
538 | if (nv_connector->underscan_hborder != value) { | |
539 | nv_connector->underscan_hborder = value; | |
540 | if (!nv_crtc || !nv_crtc->set_scale) | |
541 | return 0; | |
542 | ||
488ff207 | 543 | return nv_crtc->set_scale(nv_crtc, true); |
b29caa58 BS |
544 | } |
545 | ||
546 | return 0; | |
547 | } | |
548 | ||
549 | if (property == disp->underscan_vborder_property) { | |
550 | if (nv_connector->underscan_vborder != value) { | |
551 | nv_connector->underscan_vborder = value; | |
552 | if (!nv_crtc || !nv_crtc->set_scale) | |
553 | return 0; | |
554 | ||
488ff207 | 555 | return nv_crtc->set_scale(nv_crtc, true); |
b29caa58 BS |
556 | } |
557 | ||
558 | return 0; | |
559 | } | |
560 | ||
6ee73861 | 561 | /* Dithering */ |
de691855 BS |
562 | if (property == disp->dithering_mode) { |
563 | nv_connector->dithering_mode = value; | |
564 | if (!nv_crtc || !nv_crtc->set_dither) | |
565 | return 0; | |
566 | ||
567 | return nv_crtc->set_dither(nv_crtc, true); | |
568 | } | |
6ee73861 | 569 | |
de691855 BS |
570 | if (property == disp->dithering_depth) { |
571 | nv_connector->dithering_depth = value; | |
6ee73861 BS |
572 | if (!nv_crtc || !nv_crtc->set_dither) |
573 | return 0; | |
574 | ||
488ff207 | 575 | return nv_crtc->set_dither(nv_crtc, true); |
6ee73861 BS |
576 | } |
577 | ||
df26bc9c CB |
578 | if (nv_crtc && nv_crtc->set_color_vibrance) { |
579 | /* Hue */ | |
580 | if (property == disp->vibrant_hue_property) { | |
581 | nv_crtc->vibrant_hue = value - 90; | |
582 | return nv_crtc->set_color_vibrance(nv_crtc, true); | |
583 | } | |
584 | /* Saturation */ | |
585 | if (property == disp->color_vibrance_property) { | |
586 | nv_crtc->color_vibrance = value - 100; | |
587 | return nv_crtc->set_color_vibrance(nv_crtc, true); | |
588 | } | |
589 | } | |
590 | ||
cb75d97e | 591 | if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV) |
4a9f822f FJ |
592 | return get_slave_funcs(encoder)->set_property( |
593 | encoder, connector, property, value); | |
6ee73861 BS |
594 | |
595 | return -EINVAL; | |
596 | } | |
597 | ||
598 | static struct drm_display_mode * | |
26099a74 | 599 | nouveau_connector_native_mode(struct drm_connector *connector) |
6ee73861 | 600 | { |
d58ded76 | 601 | const struct drm_connector_helper_funcs *helper = connector->helper_private; |
77145f1c | 602 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
26099a74 BS |
603 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
604 | struct drm_device *dev = connector->dev; | |
6ee73861 BS |
605 | struct drm_display_mode *mode, *largest = NULL; |
606 | int high_w = 0, high_h = 0, high_v = 0; | |
607 | ||
26099a74 | 608 | list_for_each_entry(mode, &nv_connector->base.probed_modes, head) { |
0d9b6193 | 609 | mode->vrefresh = drm_mode_vrefresh(mode); |
a5afb775 FJ |
610 | if (helper->mode_valid(connector, mode) != MODE_OK || |
611 | (mode->flags & DRM_MODE_FLAG_INTERLACE)) | |
26099a74 BS |
612 | continue; |
613 | ||
614 | /* Use preferred mode if there is one.. */ | |
6ee73861 | 615 | if (mode->type & DRM_MODE_TYPE_PREFERRED) { |
77145f1c | 616 | NV_DEBUG(drm, "native mode from preferred\n"); |
6ee73861 BS |
617 | return drm_mode_duplicate(dev, mode); |
618 | } | |
6ee73861 | 619 | |
26099a74 BS |
620 | /* Otherwise, take the resolution with the largest width, then |
621 | * height, then vertical refresh | |
622 | */ | |
6ee73861 BS |
623 | if (mode->hdisplay < high_w) |
624 | continue; | |
625 | ||
626 | if (mode->hdisplay == high_w && mode->vdisplay < high_h) | |
627 | continue; | |
628 | ||
629 | if (mode->hdisplay == high_w && mode->vdisplay == high_h && | |
630 | mode->vrefresh < high_v) | |
631 | continue; | |
632 | ||
633 | high_w = mode->hdisplay; | |
634 | high_h = mode->vdisplay; | |
635 | high_v = mode->vrefresh; | |
636 | largest = mode; | |
637 | } | |
638 | ||
77145f1c | 639 | NV_DEBUG(drm, "native mode from largest: %dx%d@%d\n", |
6ee73861 BS |
640 | high_w, high_h, high_v); |
641 | return largest ? drm_mode_duplicate(dev, largest) : NULL; | |
642 | } | |
643 | ||
644 | struct moderec { | |
645 | int hdisplay; | |
646 | int vdisplay; | |
647 | }; | |
648 | ||
649 | static struct moderec scaler_modes[] = { | |
650 | { 1920, 1200 }, | |
651 | { 1920, 1080 }, | |
652 | { 1680, 1050 }, | |
653 | { 1600, 1200 }, | |
654 | { 1400, 1050 }, | |
655 | { 1280, 1024 }, | |
656 | { 1280, 960 }, | |
657 | { 1152, 864 }, | |
658 | { 1024, 768 }, | |
659 | { 800, 600 }, | |
660 | { 720, 400 }, | |
661 | { 640, 480 }, | |
662 | { 640, 400 }, | |
663 | { 640, 350 }, | |
664 | {} | |
665 | }; | |
666 | ||
667 | static int | |
668 | nouveau_connector_scaler_modes_add(struct drm_connector *connector) | |
669 | { | |
670 | struct nouveau_connector *nv_connector = nouveau_connector(connector); | |
671 | struct drm_display_mode *native = nv_connector->native_mode, *m; | |
672 | struct drm_device *dev = connector->dev; | |
673 | struct moderec *mode = &scaler_modes[0]; | |
674 | int modes = 0; | |
675 | ||
676 | if (!native) | |
677 | return 0; | |
678 | ||
679 | while (mode->hdisplay) { | |
680 | if (mode->hdisplay <= native->hdisplay && | |
f0d15402 BS |
681 | mode->vdisplay <= native->vdisplay && |
682 | (mode->hdisplay != native->hdisplay || | |
683 | mode->vdisplay != native->vdisplay)) { | |
6ee73861 BS |
684 | m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay, |
685 | drm_mode_vrefresh(native), false, | |
686 | false, false); | |
687 | if (!m) | |
688 | continue; | |
689 | ||
6ee73861 BS |
690 | drm_mode_probed_add(connector, m); |
691 | modes++; | |
692 | } | |
693 | ||
694 | mode++; | |
695 | } | |
696 | ||
697 | return modes; | |
698 | } | |
699 | ||
63221755 BS |
700 | static void |
701 | nouveau_connector_detect_depth(struct drm_connector *connector) | |
702 | { | |
77145f1c | 703 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
63221755 BS |
704 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
705 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; | |
77145f1c | 706 | struct nvbios *bios = &drm->vbios; |
63221755 BS |
707 | struct drm_display_mode *mode = nv_connector->native_mode; |
708 | bool duallink; | |
709 | ||
710 | /* if the edid is feeling nice enough to provide this info, use it */ | |
711 | if (nv_connector->edid && connector->display_info.bpc) | |
712 | return; | |
713 | ||
a6a17859 BS |
714 | /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */ |
715 | if (nv_connector->type == DCB_CONNECTOR_eDP) { | |
716 | connector->display_info.bpc = 6; | |
717 | return; | |
718 | } | |
719 | ||
720 | /* we're out of options unless we're LVDS, default to 8bpc */ | |
cb75d97e | 721 | if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) { |
c8435362 | 722 | connector->display_info.bpc = 8; |
63221755 | 723 | return; |
c8435362 BS |
724 | } |
725 | ||
726 | connector->display_info.bpc = 6; | |
63221755 BS |
727 | |
728 | /* LVDS: panel straps */ | |
729 | if (bios->fp_no_ddc) { | |
730 | if (bios->fp.if_is_24bit) | |
731 | connector->display_info.bpc = 8; | |
732 | return; | |
733 | } | |
734 | ||
735 | /* LVDS: DDC panel, need to first determine the number of links to | |
736 | * know which if_is_24bit flag to check... | |
737 | */ | |
738 | if (nv_connector->edid && | |
befb51e9 | 739 | nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) |
63221755 BS |
740 | duallink = ((u8 *)nv_connector->edid)[121] == 2; |
741 | else | |
742 | duallink = mode->clock >= bios->fp.duallink_transition_clk; | |
743 | ||
744 | if ((!duallink && (bios->fp.strapless_is_24bit & 1)) || | |
745 | ( duallink && (bios->fp.strapless_is_24bit & 2))) | |
746 | connector->display_info.bpc = 8; | |
747 | } | |
748 | ||
6ee73861 BS |
749 | static int |
750 | nouveau_connector_get_modes(struct drm_connector *connector) | |
751 | { | |
752 | struct drm_device *dev = connector->dev; | |
77145f1c | 753 | struct nouveau_drm *drm = nouveau_drm(dev); |
6ee73861 BS |
754 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
755 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; | |
4a9f822f | 756 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
6ee73861 BS |
757 | int ret = 0; |
758 | ||
d17f395c | 759 | /* destroy the native mode, the attached monitor could have changed. |
6ee73861 | 760 | */ |
d17f395c | 761 | if (nv_connector->native_mode) { |
6ee73861 BS |
762 | drm_mode_destroy(dev, nv_connector->native_mode); |
763 | nv_connector->native_mode = NULL; | |
764 | } | |
765 | ||
766 | if (nv_connector->edid) | |
767 | ret = drm_add_edid_modes(connector, nv_connector->edid); | |
d17f395c | 768 | else |
cb75d97e | 769 | if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS && |
d17f395c | 770 | (nv_encoder->dcb->lvdsconf.use_straps_for_mode || |
77145f1c | 771 | drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) { |
80dad869 BS |
772 | struct drm_display_mode mode; |
773 | ||
774 | nouveau_bios_fp_mode(dev, &mode); | |
775 | nv_connector->native_mode = drm_mode_duplicate(dev, &mode); | |
d17f395c | 776 | } |
6ee73861 | 777 | |
d4c2c99b BS |
778 | /* Determine display colour depth for everything except LVDS now, |
779 | * DP requires this before mode_valid() is called. | |
780 | */ | |
781 | if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS) | |
782 | nouveau_connector_detect_depth(connector); | |
783 | ||
6ee73861 BS |
784 | /* Find the native mode if this is a digital panel, if we didn't |
785 | * find any modes through DDC previously add the native mode to | |
786 | * the list of modes. | |
787 | */ | |
788 | if (!nv_connector->native_mode) | |
789 | nv_connector->native_mode = | |
26099a74 | 790 | nouveau_connector_native_mode(connector); |
6ee73861 BS |
791 | if (ret == 0 && nv_connector->native_mode) { |
792 | struct drm_display_mode *mode; | |
793 | ||
794 | mode = drm_mode_duplicate(dev, nv_connector->native_mode); | |
795 | drm_mode_probed_add(connector, mode); | |
796 | ret = 1; | |
797 | } | |
798 | ||
d4c2c99b BS |
799 | /* Determine LVDS colour depth, must happen after determining |
800 | * "native" mode as some VBIOS tables require us to use the | |
801 | * pixel clock as part of the lookup... | |
63221755 | 802 | */ |
d4c2c99b BS |
803 | if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) |
804 | nouveau_connector_detect_depth(connector); | |
63221755 | 805 | |
cb75d97e | 806 | if (nv_encoder->dcb->type == DCB_OUTPUT_TV) |
4a9f822f | 807 | ret = get_slave_funcs(encoder)->get_modes(encoder, connector); |
6ee73861 | 808 | |
befb51e9 BS |
809 | if (nv_connector->type == DCB_CONNECTOR_LVDS || |
810 | nv_connector->type == DCB_CONNECTOR_LVDS_SPWG || | |
811 | nv_connector->type == DCB_CONNECTOR_eDP) | |
6ee73861 BS |
812 | ret += nouveau_connector_scaler_modes_add(connector); |
813 | ||
814 | return ret; | |
815 | } | |
816 | ||
1f5bd443 | 817 | static unsigned |
1a0c96c0 | 818 | get_tmds_link_bandwidth(struct drm_connector *connector, bool hdmi) |
1f5bd443 FJ |
819 | { |
820 | struct nouveau_connector *nv_connector = nouveau_connector(connector); | |
77145f1c | 821 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
cb75d97e | 822 | struct dcb_output *dcb = nv_connector->detected_encoder->dcb; |
1f5bd443 | 823 | |
1a0c96c0 IM |
824 | if (hdmi) { |
825 | if (nouveau_hdmimhz > 0) | |
826 | return nouveau_hdmimhz * 1000; | |
827 | /* Note: these limits are conservative, some Fermi's | |
828 | * can do 297 MHz. Unclear how this can be determined. | |
829 | */ | |
830 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_KEPLER) | |
831 | return 297000; | |
832 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_FERMI) | |
833 | return 225000; | |
834 | } | |
1f5bd443 | 835 | if (dcb->location != DCB_LOC_ON_CHIP || |
967e7bde | 836 | drm->device.info.chipset >= 0x46) |
1f5bd443 | 837 | return 165000; |
967e7bde | 838 | else if (drm->device.info.chipset >= 0x40) |
1f5bd443 | 839 | return 155000; |
967e7bde | 840 | else if (drm->device.info.chipset >= 0x18) |
1f5bd443 FJ |
841 | return 135000; |
842 | else | |
843 | return 112000; | |
844 | } | |
845 | ||
6ee73861 BS |
846 | static int |
847 | nouveau_connector_mode_valid(struct drm_connector *connector, | |
848 | struct drm_display_mode *mode) | |
849 | { | |
6ee73861 BS |
850 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
851 | struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; | |
4a9f822f | 852 | struct drm_encoder *encoder = to_drm_encoder(nv_encoder); |
6ee73861 BS |
853 | unsigned min_clock = 25000, max_clock = min_clock; |
854 | unsigned clock = mode->clock; | |
1a0c96c0 | 855 | bool hdmi; |
6ee73861 BS |
856 | |
857 | switch (nv_encoder->dcb->type) { | |
cb75d97e | 858 | case DCB_OUTPUT_LVDS: |
26099a74 BS |
859 | if (nv_connector->native_mode && |
860 | (mode->hdisplay > nv_connector->native_mode->hdisplay || | |
861 | mode->vdisplay > nv_connector->native_mode->vdisplay)) | |
6ee73861 BS |
862 | return MODE_PANEL; |
863 | ||
864 | min_clock = 0; | |
865 | max_clock = 400000; | |
866 | break; | |
cb75d97e | 867 | case DCB_OUTPUT_TMDS: |
1a0c96c0 IM |
868 | hdmi = drm_detect_hdmi_monitor(nv_connector->edid); |
869 | max_clock = get_tmds_link_bandwidth(connector, hdmi); | |
870 | if (!hdmi && nouveau_duallink && | |
871 | nv_encoder->dcb->duallink_possible) | |
1f5bd443 | 872 | max_clock *= 2; |
6ee73861 | 873 | break; |
cb75d97e | 874 | case DCB_OUTPUT_ANALOG: |
6ee73861 BS |
875 | max_clock = nv_encoder->dcb->crtconf.maxfreq; |
876 | if (!max_clock) | |
877 | max_clock = 350000; | |
878 | break; | |
cb75d97e | 879 | case DCB_OUTPUT_TV: |
4a9f822f | 880 | return get_slave_funcs(encoder)->mode_valid(encoder, mode); |
cb75d97e | 881 | case DCB_OUTPUT_DP: |
75a1fccf BS |
882 | max_clock = nv_encoder->dp.link_nr; |
883 | max_clock *= nv_encoder->dp.link_bw; | |
d4c2c99b | 884 | clock = clock * (connector->display_info.bpc * 3) / 10; |
6ee73861 | 885 | break; |
e7cc51c5 BS |
886 | default: |
887 | BUG_ON(1); | |
888 | return MODE_BAD; | |
6ee73861 BS |
889 | } |
890 | ||
891 | if (clock < min_clock) | |
892 | return MODE_CLOCK_LOW; | |
893 | ||
894 | if (clock > max_clock) | |
895 | return MODE_CLOCK_HIGH; | |
896 | ||
897 | return MODE_OK; | |
898 | } | |
899 | ||
900 | static struct drm_encoder * | |
901 | nouveau_connector_best_encoder(struct drm_connector *connector) | |
902 | { | |
903 | struct nouveau_connector *nv_connector = nouveau_connector(connector); | |
904 | ||
905 | if (nv_connector->detected_encoder) | |
906 | return to_drm_encoder(nv_connector->detected_encoder); | |
907 | ||
908 | return NULL; | |
909 | } | |
910 | ||
911 | static const struct drm_connector_helper_funcs | |
912 | nouveau_connector_helper_funcs = { | |
913 | .get_modes = nouveau_connector_get_modes, | |
914 | .mode_valid = nouveau_connector_mode_valid, | |
915 | .best_encoder = nouveau_connector_best_encoder, | |
916 | }; | |
917 | ||
918 | static const struct drm_connector_funcs | |
919 | nouveau_connector_funcs = { | |
920 | .dpms = drm_helper_connector_dpms, | |
6ee73861 BS |
921 | .detect = nouveau_connector_detect, |
922 | .destroy = nouveau_connector_destroy, | |
923 | .fill_modes = drm_helper_probe_single_connector_modes, | |
924 | .set_property = nouveau_connector_set_property, | |
925 | .force = nouveau_connector_force | |
926 | }; | |
927 | ||
d17f395c BS |
928 | static const struct drm_connector_funcs |
929 | nouveau_connector_funcs_lvds = { | |
930 | .dpms = drm_helper_connector_dpms, | |
d17f395c BS |
931 | .detect = nouveau_connector_detect_lvds, |
932 | .destroy = nouveau_connector_destroy, | |
933 | .fill_modes = drm_helper_probe_single_connector_modes, | |
934 | .set_property = nouveau_connector_set_property, | |
935 | .force = nouveau_connector_force | |
936 | }; | |
6ee73861 | 937 | |
9a69a9ac | 938 | static int |
4874322e BS |
939 | nouveau_connector_dp_dpms(struct drm_connector *connector, int mode) |
940 | { | |
941 | struct nouveau_encoder *nv_encoder = NULL; | |
942 | ||
943 | if (connector->encoder) | |
944 | nv_encoder = nouveau_encoder(connector->encoder); | |
945 | if (nv_encoder && nv_encoder->dcb && | |
946 | nv_encoder->dcb->type == DCB_OUTPUT_DP) { | |
947 | if (mode == DRM_MODE_DPMS_ON) { | |
948 | u8 data = DP_SET_POWER_D0; | |
2aa5eac5 | 949 | nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1); |
4874322e BS |
950 | usleep_range(1000, 2000); |
951 | } else { | |
952 | u8 data = DP_SET_POWER_D3; | |
2aa5eac5 | 953 | nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1); |
4874322e BS |
954 | } |
955 | } | |
956 | ||
9a69a9ac | 957 | return drm_helper_connector_dpms(connector, mode); |
4874322e BS |
958 | } |
959 | ||
960 | static const struct drm_connector_funcs | |
961 | nouveau_connector_funcs_dp = { | |
962 | .dpms = nouveau_connector_dp_dpms, | |
4874322e BS |
963 | .detect = nouveau_connector_detect, |
964 | .destroy = nouveau_connector_destroy, | |
965 | .fill_modes = drm_helper_probe_single_connector_modes, | |
966 | .set_property = nouveau_connector_set_property, | |
967 | .force = nouveau_connector_force | |
968 | }; | |
969 | ||
79ca2770 | 970 | static int |
80bc340b | 971 | nouveau_connector_hotplug(struct nvif_notify *notify) |
4f47643d BS |
972 | { |
973 | struct nouveau_connector *nv_connector = | |
79ca2770 | 974 | container_of(notify, typeof(*nv_connector), hpd); |
4f47643d | 975 | struct drm_connector *connector = &nv_connector->base; |
456b0579 | 976 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
79ca2770 | 977 | const struct nvif_notify_conn_rep_v0 *rep = notify->data; |
456b0579 | 978 | const char *name = connector->name; |
4f47643d | 979 | |
79ca2770 | 980 | if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) { |
456b0579 | 981 | } else { |
79ca2770 | 982 | bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG); |
4f47643d | 983 | |
456b0579 | 984 | NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name); |
4f47643d | 985 | |
456b0579 BS |
986 | if (plugged) |
987 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); | |
988 | else | |
989 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); | |
990 | drm_helper_hpd_irq_event(connector->dev); | |
991 | } | |
992 | ||
80bc340b | 993 | return NVIF_NOTIFY_KEEP; |
4f47643d BS |
994 | } |
995 | ||
8894f491 | 996 | static ssize_t |
2aa5eac5 | 997 | nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg) |
8894f491 BS |
998 | { |
999 | struct nouveau_connector *nv_connector = | |
2aa5eac5 | 1000 | container_of(obj, typeof(*nv_connector), aux); |
8894f491 | 1001 | struct nouveau_encoder *nv_encoder; |
2aa5eac5 | 1002 | struct nvkm_i2c_aux *aux; |
8894f491 BS |
1003 | int ret; |
1004 | ||
1005 | nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP); | |
2aa5eac5 | 1006 | if (!nv_encoder || !(aux = nv_encoder->aux)) |
8894f491 BS |
1007 | return -ENODEV; |
1008 | if (WARN_ON(msg->size > 16)) | |
1009 | return -E2BIG; | |
1010 | if (msg->size == 0) | |
1011 | return msg->size; | |
1012 | ||
2aa5eac5 | 1013 | ret = nvkm_i2c_aux_acquire(aux); |
8894f491 BS |
1014 | if (ret) |
1015 | return ret; | |
1016 | ||
2aa5eac5 BS |
1017 | ret = nvkm_i2c_aux_xfer(aux, false, msg->request, msg->address, |
1018 | msg->buffer, msg->size); | |
1019 | nvkm_i2c_aux_release(aux); | |
8894f491 BS |
1020 | if (ret >= 0) { |
1021 | msg->reply = ret; | |
1022 | return msg->size; | |
1023 | } | |
1024 | ||
1025 | return ret; | |
1026 | } | |
1027 | ||
befb51e9 BS |
1028 | static int |
1029 | drm_conntype_from_dcb(enum dcb_connector_type dcb) | |
1030 | { | |
1031 | switch (dcb) { | |
1032 | case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA; | |
1033 | case DCB_CONNECTOR_TV_0 : | |
1034 | case DCB_CONNECTOR_TV_1 : | |
1035 | case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV; | |
fa2c113a BS |
1036 | case DCB_CONNECTOR_DMS59_0 : |
1037 | case DCB_CONNECTOR_DMS59_1 : | |
befb51e9 BS |
1038 | case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII; |
1039 | case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID; | |
1040 | case DCB_CONNECTOR_LVDS : | |
1041 | case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS; | |
4abb410a BS |
1042 | case DCB_CONNECTOR_DMS59_DP0: |
1043 | case DCB_CONNECTOR_DMS59_DP1: | |
befb51e9 BS |
1044 | case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort; |
1045 | case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP; | |
1046 | case DCB_CONNECTOR_HDMI_0 : | |
6bd9293e BS |
1047 | case DCB_CONNECTOR_HDMI_1 : |
1048 | case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA; | |
befb51e9 BS |
1049 | default: |
1050 | break; | |
1051 | } | |
1052 | ||
1053 | return DRM_MODE_CONNECTOR_Unknown; | |
1054 | } | |
1055 | ||
8f1a6086 BS |
1056 | struct drm_connector * |
1057 | nouveau_connector_create(struct drm_device *dev, int index) | |
6ee73861 | 1058 | { |
d17f395c | 1059 | const struct drm_connector_funcs *funcs = &nouveau_connector_funcs; |
77145f1c | 1060 | struct nouveau_drm *drm = nouveau_drm(dev); |
77145f1c | 1061 | struct nouveau_display *disp = nouveau_display(dev); |
6ee73861 BS |
1062 | struct nouveau_connector *nv_connector = NULL; |
1063 | struct drm_connector *connector; | |
2fa67f12 | 1064 | int type, ret = 0; |
befb51e9 | 1065 | bool dummy; |
6ee73861 | 1066 | |
befb51e9 BS |
1067 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
1068 | nv_connector = nouveau_connector(connector); | |
1069 | if (nv_connector->index == index) | |
1070 | return connector; | |
6ee73861 BS |
1071 | } |
1072 | ||
7f612d87 BS |
1073 | nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL); |
1074 | if (!nv_connector) | |
8f1a6086 | 1075 | return ERR_PTR(-ENOMEM); |
befb51e9 | 1076 | |
7f612d87 | 1077 | connector = &nv_connector->base; |
befb51e9 BS |
1078 | nv_connector->index = index; |
1079 | ||
1080 | /* attempt to parse vbios connector type and hotplug gpio */ | |
cb75d97e | 1081 | nv_connector->dcb = olddcb_conn(dev, index); |
befb51e9 | 1082 | if (nv_connector->dcb) { |
befb51e9 | 1083 | u32 entry = ROM16(nv_connector->dcb[0]); |
cb75d97e | 1084 | if (olddcb_conntab(dev)[3] >= 4) |
befb51e9 BS |
1085 | entry |= (u32)ROM16(nv_connector->dcb[2]) << 16; |
1086 | ||
befb51e9 BS |
1087 | nv_connector->type = nv_connector->dcb[0]; |
1088 | if (drm_conntype_from_dcb(nv_connector->type) == | |
1089 | DRM_MODE_CONNECTOR_Unknown) { | |
77145f1c | 1090 | NV_WARN(drm, "unknown connector type %02x\n", |
befb51e9 BS |
1091 | nv_connector->type); |
1092 | nv_connector->type = DCB_CONNECTOR_NONE; | |
1093 | } | |
7f612d87 | 1094 | |
befb51e9 BS |
1095 | /* Gigabyte NX85T */ |
1096 | if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) { | |
1097 | if (nv_connector->type == DCB_CONNECTOR_HDMI_1) | |
1098 | nv_connector->type = DCB_CONNECTOR_DVI_I; | |
1099 | } | |
6ee73861 | 1100 | |
befb51e9 BS |
1101 | /* Gigabyte GV-NX86T512H */ |
1102 | if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) { | |
1103 | if (nv_connector->type == DCB_CONNECTOR_HDMI_1) | |
1104 | nv_connector->type = DCB_CONNECTOR_DVI_I; | |
1105 | } | |
1106 | } else { | |
1107 | nv_connector->type = DCB_CONNECTOR_NONE; | |
befb51e9 BS |
1108 | } |
1109 | ||
1110 | /* no vbios data, or an unknown dcb connector type - attempt to | |
1111 | * figure out something suitable ourselves | |
1112 | */ | |
1113 | if (nv_connector->type == DCB_CONNECTOR_NONE) { | |
77145f1c BS |
1114 | struct nouveau_drm *drm = nouveau_drm(dev); |
1115 | struct dcb_table *dcbt = &drm->vbios.dcb; | |
befb51e9 BS |
1116 | u32 encoders = 0; |
1117 | int i; | |
1118 | ||
1119 | for (i = 0; i < dcbt->entries; i++) { | |
1120 | if (dcbt->entry[i].connector == nv_connector->index) | |
1121 | encoders |= (1 << dcbt->entry[i].type); | |
1122 | } | |
6ee73861 | 1123 | |
cb75d97e BS |
1124 | if (encoders & (1 << DCB_OUTPUT_DP)) { |
1125 | if (encoders & (1 << DCB_OUTPUT_TMDS)) | |
befb51e9 BS |
1126 | nv_connector->type = DCB_CONNECTOR_DP; |
1127 | else | |
1128 | nv_connector->type = DCB_CONNECTOR_eDP; | |
1129 | } else | |
cb75d97e BS |
1130 | if (encoders & (1 << DCB_OUTPUT_TMDS)) { |
1131 | if (encoders & (1 << DCB_OUTPUT_ANALOG)) | |
befb51e9 BS |
1132 | nv_connector->type = DCB_CONNECTOR_DVI_I; |
1133 | else | |
1134 | nv_connector->type = DCB_CONNECTOR_DVI_D; | |
1135 | } else | |
cb75d97e | 1136 | if (encoders & (1 << DCB_OUTPUT_ANALOG)) { |
befb51e9 BS |
1137 | nv_connector->type = DCB_CONNECTOR_VGA; |
1138 | } else | |
cb75d97e | 1139 | if (encoders & (1 << DCB_OUTPUT_LVDS)) { |
befb51e9 BS |
1140 | nv_connector->type = DCB_CONNECTOR_LVDS; |
1141 | } else | |
cb75d97e | 1142 | if (encoders & (1 << DCB_OUTPUT_TV)) { |
befb51e9 BS |
1143 | nv_connector->type = DCB_CONNECTOR_TV_0; |
1144 | } | |
1145 | } | |
2fa67f12 | 1146 | |
8894f491 BS |
1147 | switch ((type = drm_conntype_from_dcb(nv_connector->type))) { |
1148 | case DRM_MODE_CONNECTOR_LVDS: | |
befb51e9 | 1149 | ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy); |
2fa67f12 | 1150 | if (ret) { |
77145f1c | 1151 | NV_ERROR(drm, "Error parsing LVDS table, disabling\n"); |
befb51e9 BS |
1152 | kfree(nv_connector); |
1153 | return ERR_PTR(ret); | |
2fa67f12 | 1154 | } |
befb51e9 BS |
1155 | |
1156 | funcs = &nouveau_connector_funcs_lvds; | |
8894f491 BS |
1157 | break; |
1158 | case DRM_MODE_CONNECTOR_DisplayPort: | |
1159 | case DRM_MODE_CONNECTOR_eDP: | |
1160 | nv_connector->aux.dev = dev->dev; | |
1161 | nv_connector->aux.transfer = nouveau_connector_aux_xfer; | |
1162 | ret = drm_dp_aux_register(&nv_connector->aux); | |
1163 | if (ret) { | |
1164 | NV_ERROR(drm, "failed to register aux channel\n"); | |
1165 | kfree(nv_connector); | |
1166 | return ERR_PTR(ret); | |
1167 | } | |
1168 | ||
4874322e | 1169 | funcs = &nouveau_connector_funcs_dp; |
8894f491 BS |
1170 | break; |
1171 | default: | |
1172 | funcs = &nouveau_connector_funcs; | |
1173 | break; | |
7f612d87 BS |
1174 | } |
1175 | ||
befb51e9 BS |
1176 | /* defaults, will get overridden in detect() */ |
1177 | connector->interlace_allowed = false; | |
1178 | connector->doublescan_allowed = false; | |
1179 | ||
1180 | drm_connector_init(dev, connector, funcs, type); | |
1181 | drm_connector_helper_add(connector, &nouveau_connector_helper_funcs); | |
1182 | ||
6ee73861 | 1183 | /* Init DVI-I specific properties */ |
befb51e9 | 1184 | if (nv_connector->type == DCB_CONNECTOR_DVI_I) |
2db83827 | 1185 | drm_object_attach_property(&connector->base, dev->mode_config.dvi_i_subconnector_property, 0); |
6ee73861 | 1186 | |
b29caa58 | 1187 | /* Add overscan compensation options to digital outputs */ |
de691855 | 1188 | if (disp->underscan_property && |
fa2c113a BS |
1189 | (type == DRM_MODE_CONNECTOR_DVID || |
1190 | type == DRM_MODE_CONNECTOR_DVII || | |
1191 | type == DRM_MODE_CONNECTOR_HDMIA || | |
1192 | type == DRM_MODE_CONNECTOR_DisplayPort)) { | |
2db83827 | 1193 | drm_object_attach_property(&connector->base, |
b29caa58 BS |
1194 | disp->underscan_property, |
1195 | UNDERSCAN_OFF); | |
2db83827 | 1196 | drm_object_attach_property(&connector->base, |
b29caa58 BS |
1197 | disp->underscan_hborder_property, |
1198 | 0); | |
2db83827 | 1199 | drm_object_attach_property(&connector->base, |
b29caa58 BS |
1200 | disp->underscan_vborder_property, |
1201 | 0); | |
1202 | } | |
1203 | ||
df26bc9c CB |
1204 | /* Add hue and saturation options */ |
1205 | if (disp->vibrant_hue_property) | |
2db83827 | 1206 | drm_object_attach_property(&connector->base, |
df26bc9c CB |
1207 | disp->vibrant_hue_property, |
1208 | 90); | |
1209 | if (disp->color_vibrance_property) | |
2db83827 | 1210 | drm_object_attach_property(&connector->base, |
df26bc9c CB |
1211 | disp->color_vibrance_property, |
1212 | 150); | |
1213 | ||
7d95216e | 1214 | /* default scaling mode */ |
befb51e9 | 1215 | switch (nv_connector->type) { |
0ea5fe8a BS |
1216 | case DCB_CONNECTOR_LVDS: |
1217 | case DCB_CONNECTOR_LVDS_SPWG: | |
1218 | case DCB_CONNECTOR_eDP: | |
1219 | /* see note in nouveau_connector_set_property() */ | |
1220 | if (disp->disp.oclass < NV50_DISP) { | |
1221 | nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; | |
1222 | break; | |
1223 | } | |
be079e97 BS |
1224 | nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; |
1225 | break; | |
1226 | default: | |
0ea5fe8a | 1227 | nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; |
7d95216e BS |
1228 | break; |
1229 | } | |
be079e97 | 1230 | |
7d95216e BS |
1231 | /* scaling mode property */ |
1232 | switch (nv_connector->type) { | |
1233 | case DCB_CONNECTOR_TV_0: | |
1234 | case DCB_CONNECTOR_TV_1: | |
1235 | case DCB_CONNECTOR_TV_3: | |
1236 | break; | |
1237 | case DCB_CONNECTOR_VGA: | |
1238 | if (disp->disp.oclass < NV50_DISP) | |
1239 | break; /* can only scale on DFPs */ | |
1240 | /* fall-through */ | |
1241 | default: | |
1242 | drm_object_attach_property(&connector->base, dev->mode_config. | |
1243 | scaling_mode_property, | |
1244 | nv_connector->scaling_mode); | |
1245 | break; | |
1246 | } | |
1247 | ||
1248 | /* dithering properties */ | |
1249 | switch (nv_connector->type) { | |
1250 | case DCB_CONNECTOR_TV_0: | |
1251 | case DCB_CONNECTOR_TV_1: | |
1252 | case DCB_CONNECTOR_TV_3: | |
1253 | case DCB_CONNECTOR_VGA: | |
1254 | break; | |
1255 | default: | |
de691855 | 1256 | if (disp->dithering_mode) { |
2db83827 | 1257 | drm_object_attach_property(&connector->base, |
7d95216e BS |
1258 | disp->dithering_mode, |
1259 | nv_connector-> | |
1260 | dithering_mode); | |
1261 | nv_connector->dithering_mode = DITHERING_MODE_AUTO; | |
de691855 BS |
1262 | } |
1263 | if (disp->dithering_depth) { | |
2db83827 | 1264 | drm_object_attach_property(&connector->base, |
7d95216e BS |
1265 | disp->dithering_depth, |
1266 | nv_connector-> | |
1267 | dithering_depth); | |
1268 | nv_connector->dithering_depth = DITHERING_DEPTH_AUTO; | |
de691855 | 1269 | } |
be079e97 | 1270 | break; |
6ee73861 BS |
1271 | } |
1272 | ||
a01ca78c BS |
1273 | ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true, |
1274 | NV04_DISP_NTFY_CONN, | |
79ca2770 BS |
1275 | &(struct nvif_notify_conn_req_v0) { |
1276 | .mask = NVIF_NOTIFY_CONN_V0_ANY, | |
1277 | .conn = index, | |
1278 | }, | |
1279 | sizeof(struct nvif_notify_conn_req_v0), | |
1280 | sizeof(struct nvif_notify_conn_rep_v0), | |
1281 | &nv_connector->hpd); | |
456b0579 BS |
1282 | if (ret) |
1283 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; | |
1284 | else | |
4f47643d | 1285 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
fce2bad0 | 1286 | |
34ea3d38 | 1287 | drm_connector_register(connector); |
befb51e9 | 1288 | return connector; |
6ee73861 | 1289 | } |