nouveau_connector.c 36 KB

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