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