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