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