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