nouveau_connector.c 40 KB

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