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