nouveau_connector.c 37 KB

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