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