nouveau_connector.c 36 KB

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