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