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