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