nouveau_connector.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  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.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. __drm_atomic_helper_connector_destroy_state(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.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.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 drm_device *dev = connector->dev;
  329. struct nouveau_encoder *nv_encoder;
  330. struct drm_encoder *enc;
  331. int i, id;
  332. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  333. id = connector->encoder_ids[i];
  334. if (!id)
  335. break;
  336. enc = drm_encoder_find(dev, id);
  337. if (!enc)
  338. continue;
  339. nv_encoder = nouveau_encoder(enc);
  340. if (type == DCB_OUTPUT_ANY ||
  341. (nv_encoder->dcb && nv_encoder->dcb->type == type))
  342. return nv_encoder;
  343. }
  344. return NULL;
  345. }
  346. struct nouveau_connector *
  347. nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
  348. {
  349. struct drm_device *dev = to_drm_encoder(encoder)->dev;
  350. struct drm_connector *drm_connector;
  351. list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
  352. if (drm_connector->encoder == to_drm_encoder(encoder))
  353. return nouveau_connector(drm_connector);
  354. }
  355. return NULL;
  356. }
  357. static void
  358. nouveau_connector_destroy(struct drm_connector *connector)
  359. {
  360. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  361. nvif_notify_fini(&nv_connector->hpd);
  362. kfree(nv_connector->edid);
  363. drm_connector_unregister(connector);
  364. drm_connector_cleanup(connector);
  365. if (nv_connector->aux.transfer)
  366. drm_dp_aux_unregister(&nv_connector->aux);
  367. kfree(connector);
  368. }
  369. static struct nouveau_encoder *
  370. nouveau_connector_ddc_detect(struct drm_connector *connector)
  371. {
  372. struct drm_device *dev = connector->dev;
  373. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  374. struct nouveau_drm *drm = nouveau_drm(dev);
  375. struct nvkm_gpio *gpio = nvxx_gpio(&drm->device);
  376. struct nouveau_encoder *nv_encoder;
  377. struct drm_encoder *encoder;
  378. int i, panel = -ENODEV;
  379. /* eDP panels need powering on by us (if the VBIOS doesn't default it
  380. * to on) before doing any AUX channel transactions. LVDS panel power
  381. * is handled by the SOR itself, and not required for LVDS DDC.
  382. */
  383. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  384. panel = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
  385. if (panel == 0) {
  386. nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
  387. msleep(300);
  388. }
  389. }
  390. for (i = 0; nv_encoder = NULL, i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  391. int id = connector->encoder_ids[i];
  392. if (id == 0)
  393. break;
  394. encoder = drm_encoder_find(dev, id);
  395. if (!encoder)
  396. continue;
  397. nv_encoder = nouveau_encoder(encoder);
  398. if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
  399. int ret = nouveau_dp_detect(nv_encoder);
  400. if (ret == NOUVEAU_DP_MST)
  401. return NULL;
  402. if (ret == NOUVEAU_DP_SST)
  403. break;
  404. } else
  405. if ((vga_switcheroo_handler_flags() &
  406. VGA_SWITCHEROO_CAN_SWITCH_DDC) &&
  407. nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
  408. nv_encoder->i2c) {
  409. int ret;
  410. vga_switcheroo_lock_ddc(dev->pdev);
  411. ret = nvkm_probe_i2c(nv_encoder->i2c, 0x50);
  412. vga_switcheroo_unlock_ddc(dev->pdev);
  413. if (ret)
  414. break;
  415. } else
  416. if (nv_encoder->i2c) {
  417. if (nvkm_probe_i2c(nv_encoder->i2c, 0x50))
  418. break;
  419. }
  420. }
  421. /* eDP panel not detected, restore panel power GPIO to previous
  422. * state to avoid confusing the SOR for other output types.
  423. */
  424. if (!nv_encoder && panel == 0)
  425. nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel);
  426. return nv_encoder;
  427. }
  428. static struct nouveau_encoder *
  429. nouveau_connector_of_detect(struct drm_connector *connector)
  430. {
  431. #ifdef __powerpc__
  432. struct drm_device *dev = connector->dev;
  433. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  434. struct nouveau_encoder *nv_encoder;
  435. struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
  436. if (!dn ||
  437. !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) ||
  438. (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG))))
  439. return NULL;
  440. for_each_child_of_node(dn, cn) {
  441. const char *name = of_get_property(cn, "name", NULL);
  442. const void *edid = of_get_property(cn, "EDID", NULL);
  443. int idx = name ? name[strlen(name) - 1] - 'A' : 0;
  444. if (nv_encoder->dcb->i2c_index == idx && edid) {
  445. nv_connector->edid =
  446. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  447. of_node_put(cn);
  448. return nv_encoder;
  449. }
  450. }
  451. #endif
  452. return NULL;
  453. }
  454. static void
  455. nouveau_connector_set_encoder(struct drm_connector *connector,
  456. struct nouveau_encoder *nv_encoder)
  457. {
  458. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  459. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  460. struct drm_device *dev = connector->dev;
  461. if (nv_connector->detected_encoder == nv_encoder)
  462. return;
  463. nv_connector->detected_encoder = nv_encoder;
  464. if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
  465. connector->interlace_allowed = true;
  466. connector->doublescan_allowed = true;
  467. } else
  468. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS ||
  469. nv_encoder->dcb->type == DCB_OUTPUT_TMDS) {
  470. connector->doublescan_allowed = false;
  471. connector->interlace_allowed = false;
  472. } else {
  473. connector->doublescan_allowed = true;
  474. if (drm->device.info.family == NV_DEVICE_INFO_V0_KELVIN ||
  475. (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
  476. (dev->pdev->device & 0x0ff0) != 0x0100 &&
  477. (dev->pdev->device & 0x0ff0) != 0x0150))
  478. /* HW is broken */
  479. connector->interlace_allowed = false;
  480. else
  481. connector->interlace_allowed = true;
  482. }
  483. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  484. drm_object_property_set_value(&connector->base,
  485. dev->mode_config.dvi_i_subconnector_property,
  486. nv_encoder->dcb->type == DCB_OUTPUT_TMDS ?
  487. DRM_MODE_SUBCONNECTOR_DVID :
  488. DRM_MODE_SUBCONNECTOR_DVIA);
  489. }
  490. }
  491. static enum drm_connector_status
  492. nouveau_connector_detect(struct drm_connector *connector, bool force)
  493. {
  494. struct drm_device *dev = connector->dev;
  495. struct nouveau_drm *drm = nouveau_drm(dev);
  496. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  497. struct nouveau_encoder *nv_encoder = NULL;
  498. struct nouveau_encoder *nv_partner;
  499. struct i2c_adapter *i2c;
  500. int type;
  501. int ret;
  502. enum drm_connector_status conn_status = connector_status_disconnected;
  503. /* Cleanup the previous EDID block. */
  504. if (nv_connector->edid) {
  505. drm_mode_connector_update_edid_property(connector, NULL);
  506. kfree(nv_connector->edid);
  507. nv_connector->edid = NULL;
  508. }
  509. ret = pm_runtime_get_sync(connector->dev->dev);
  510. if (ret < 0 && ret != -EACCES)
  511. return conn_status;
  512. nv_encoder = nouveau_connector_ddc_detect(connector);
  513. if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
  514. if ((vga_switcheroo_handler_flags() &
  515. VGA_SWITCHEROO_CAN_SWITCH_DDC) &&
  516. nv_connector->type == DCB_CONNECTOR_LVDS)
  517. nv_connector->edid = drm_get_edid_switcheroo(connector,
  518. i2c);
  519. else
  520. nv_connector->edid = drm_get_edid(connector, i2c);
  521. drm_mode_connector_update_edid_property(connector,
  522. nv_connector->edid);
  523. if (!nv_connector->edid) {
  524. NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
  525. connector->name);
  526. goto detect_analog;
  527. }
  528. /* Override encoder type for DVI-I based on whether EDID
  529. * says the display is digital or analog, both use the
  530. * same i2c channel so the value returned from ddc_detect
  531. * isn't necessarily correct.
  532. */
  533. nv_partner = NULL;
  534. if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
  535. nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
  536. if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
  537. nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
  538. if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
  539. nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
  540. (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
  541. nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
  542. if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
  543. type = DCB_OUTPUT_TMDS;
  544. else
  545. type = DCB_OUTPUT_ANALOG;
  546. nv_encoder = find_encoder(connector, type);
  547. }
  548. nouveau_connector_set_encoder(connector, nv_encoder);
  549. conn_status = connector_status_connected;
  550. goto out;
  551. }
  552. nv_encoder = nouveau_connector_of_detect(connector);
  553. if (nv_encoder) {
  554. nouveau_connector_set_encoder(connector, nv_encoder);
  555. conn_status = connector_status_connected;
  556. goto out;
  557. }
  558. detect_analog:
  559. nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
  560. if (!nv_encoder && !nouveau_tv_disable)
  561. nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
  562. if (nv_encoder && force) {
  563. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  564. const struct drm_encoder_helper_funcs *helper =
  565. encoder->helper_private;
  566. if (helper->detect(encoder, connector) ==
  567. connector_status_connected) {
  568. nouveau_connector_set_encoder(connector, nv_encoder);
  569. conn_status = connector_status_connected;
  570. goto out;
  571. }
  572. }
  573. out:
  574. pm_runtime_mark_last_busy(connector->dev->dev);
  575. pm_runtime_put_autosuspend(connector->dev->dev);
  576. return conn_status;
  577. }
  578. static enum drm_connector_status
  579. nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
  580. {
  581. struct drm_device *dev = connector->dev;
  582. struct nouveau_drm *drm = nouveau_drm(dev);
  583. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  584. struct nouveau_encoder *nv_encoder = NULL;
  585. enum drm_connector_status status = connector_status_disconnected;
  586. /* Cleanup the previous EDID block. */
  587. if (nv_connector->edid) {
  588. drm_mode_connector_update_edid_property(connector, NULL);
  589. kfree(nv_connector->edid);
  590. nv_connector->edid = NULL;
  591. }
  592. nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
  593. if (!nv_encoder)
  594. return connector_status_disconnected;
  595. /* Try retrieving EDID via DDC */
  596. if (!drm->vbios.fp_no_ddc) {
  597. status = nouveau_connector_detect(connector, force);
  598. if (status == connector_status_connected)
  599. goto out;
  600. }
  601. /* On some laptops (Sony, i'm looking at you) there appears to
  602. * be no direct way of accessing the panel's EDID. The only
  603. * option available to us appears to be to ask ACPI for help..
  604. *
  605. * It's important this check's before trying straps, one of the
  606. * said manufacturer's laptops are configured in such a way
  607. * the nouveau decides an entry in the VBIOS FP mode table is
  608. * valid - it's not (rh#613284)
  609. */
  610. if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
  611. if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
  612. status = connector_status_connected;
  613. goto out;
  614. }
  615. }
  616. /* If no EDID found above, and the VBIOS indicates a hardcoded
  617. * modeline is avalilable for the panel, set it as the panel's
  618. * native mode and exit.
  619. */
  620. if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
  621. nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
  622. status = connector_status_connected;
  623. goto out;
  624. }
  625. /* Still nothing, some VBIOS images have a hardcoded EDID block
  626. * stored for the panel stored in them.
  627. */
  628. if (!drm->vbios.fp_no_ddc) {
  629. struct edid *edid =
  630. (struct edid *)nouveau_bios_embedded_edid(dev);
  631. if (edid) {
  632. nv_connector->edid =
  633. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  634. if (nv_connector->edid)
  635. status = connector_status_connected;
  636. }
  637. }
  638. out:
  639. #if defined(CONFIG_ACPI_BUTTON) || \
  640. (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
  641. if (status == connector_status_connected &&
  642. !nouveau_ignorelid && !acpi_lid_open())
  643. status = connector_status_unknown;
  644. #endif
  645. drm_mode_connector_update_edid_property(connector, nv_connector->edid);
  646. nouveau_connector_set_encoder(connector, nv_encoder);
  647. return status;
  648. }
  649. static void
  650. nouveau_connector_force(struct drm_connector *connector)
  651. {
  652. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  653. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  654. struct nouveau_encoder *nv_encoder;
  655. int type;
  656. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  657. if (connector->force == DRM_FORCE_ON_DIGITAL)
  658. type = DCB_OUTPUT_TMDS;
  659. else
  660. type = DCB_OUTPUT_ANALOG;
  661. } else
  662. type = DCB_OUTPUT_ANY;
  663. nv_encoder = find_encoder(connector, type);
  664. if (!nv_encoder) {
  665. NV_ERROR(drm, "can't find encoder to force %s on!\n",
  666. connector->name);
  667. connector->status = connector_status_disconnected;
  668. return;
  669. }
  670. nouveau_connector_set_encoder(connector, nv_encoder);
  671. }
  672. static int
  673. nouveau_connector_set_property(struct drm_connector *connector,
  674. struct drm_property *property, uint64_t value)
  675. {
  676. struct nouveau_conn_atom *asyc = nouveau_conn_atom(connector->state);
  677. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  678. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  679. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  680. int ret;
  681. if (drm_drv_uses_atomic_modeset(connector->dev))
  682. return drm_atomic_helper_connector_set_property(connector, property, value);
  683. ret = connector->funcs->atomic_set_property(&nv_connector->base,
  684. &asyc->state,
  685. property, value);
  686. if (ret) {
  687. if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
  688. return get_slave_funcs(encoder)->set_property(
  689. encoder, connector, property, value);
  690. return ret;
  691. }
  692. nv_connector->scaling_mode = asyc->scaler.mode;
  693. nv_connector->dithering_mode = asyc->dither.mode;
  694. if (connector->encoder && connector->encoder->crtc) {
  695. ret = drm_crtc_helper_set_mode(connector->encoder->crtc,
  696. &connector->encoder->crtc->mode,
  697. connector->encoder->crtc->x,
  698. connector->encoder->crtc->y,
  699. NULL);
  700. if (!ret)
  701. return -EINVAL;
  702. }
  703. return 0;
  704. }
  705. struct moderec {
  706. int hdisplay;
  707. int vdisplay;
  708. };
  709. static struct moderec scaler_modes[] = {
  710. { 1920, 1200 },
  711. { 1920, 1080 },
  712. { 1680, 1050 },
  713. { 1600, 1200 },
  714. { 1400, 1050 },
  715. { 1280, 1024 },
  716. { 1280, 960 },
  717. { 1152, 864 },
  718. { 1024, 768 },
  719. { 800, 600 },
  720. { 720, 400 },
  721. { 640, 480 },
  722. { 640, 400 },
  723. { 640, 350 },
  724. {}
  725. };
  726. static int
  727. nouveau_connector_scaler_modes_add(struct drm_connector *connector)
  728. {
  729. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  730. struct drm_display_mode *native = nv_connector->native_mode, *m;
  731. struct drm_device *dev = connector->dev;
  732. struct moderec *mode = &scaler_modes[0];
  733. int modes = 0;
  734. if (!native)
  735. return 0;
  736. while (mode->hdisplay) {
  737. if (mode->hdisplay <= native->hdisplay &&
  738. mode->vdisplay <= native->vdisplay &&
  739. (mode->hdisplay != native->hdisplay ||
  740. mode->vdisplay != native->vdisplay)) {
  741. m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
  742. drm_mode_vrefresh(native), false,
  743. false, false);
  744. if (!m)
  745. continue;
  746. drm_mode_probed_add(connector, m);
  747. modes++;
  748. }
  749. mode++;
  750. }
  751. return modes;
  752. }
  753. static void
  754. nouveau_connector_detect_depth(struct drm_connector *connector)
  755. {
  756. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  757. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  758. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  759. struct nvbios *bios = &drm->vbios;
  760. struct drm_display_mode *mode = nv_connector->native_mode;
  761. bool duallink;
  762. /* if the edid is feeling nice enough to provide this info, use it */
  763. if (nv_connector->edid && connector->display_info.bpc)
  764. return;
  765. /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
  766. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  767. connector->display_info.bpc = 6;
  768. return;
  769. }
  770. /* we're out of options unless we're LVDS, default to 8bpc */
  771. if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
  772. connector->display_info.bpc = 8;
  773. return;
  774. }
  775. connector->display_info.bpc = 6;
  776. /* LVDS: panel straps */
  777. if (bios->fp_no_ddc) {
  778. if (bios->fp.if_is_24bit)
  779. connector->display_info.bpc = 8;
  780. return;
  781. }
  782. /* LVDS: DDC panel, need to first determine the number of links to
  783. * know which if_is_24bit flag to check...
  784. */
  785. if (nv_connector->edid &&
  786. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
  787. duallink = ((u8 *)nv_connector->edid)[121] == 2;
  788. else
  789. duallink = mode->clock >= bios->fp.duallink_transition_clk;
  790. if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
  791. ( duallink && (bios->fp.strapless_is_24bit & 2)))
  792. connector->display_info.bpc = 8;
  793. }
  794. static int
  795. nouveau_connector_get_modes(struct drm_connector *connector)
  796. {
  797. struct drm_device *dev = connector->dev;
  798. struct nouveau_drm *drm = nouveau_drm(dev);
  799. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  800. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  801. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  802. int ret = 0;
  803. /* destroy the native mode, the attached monitor could have changed.
  804. */
  805. if (nv_connector->native_mode) {
  806. drm_mode_destroy(dev, nv_connector->native_mode);
  807. nv_connector->native_mode = NULL;
  808. }
  809. if (nv_connector->edid)
  810. ret = drm_add_edid_modes(connector, nv_connector->edid);
  811. else
  812. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
  813. (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
  814. drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
  815. struct drm_display_mode mode;
  816. nouveau_bios_fp_mode(dev, &mode);
  817. nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
  818. }
  819. /* Determine display colour depth for everything except LVDS now,
  820. * DP requires this before mode_valid() is called.
  821. */
  822. if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
  823. nouveau_connector_detect_depth(connector);
  824. /* Find the native mode if this is a digital panel, if we didn't
  825. * find any modes through DDC previously add the native mode to
  826. * the list of modes.
  827. */
  828. if (!nv_connector->native_mode)
  829. nv_connector->native_mode = nouveau_conn_native_mode(connector);
  830. if (ret == 0 && nv_connector->native_mode) {
  831. struct drm_display_mode *mode;
  832. mode = drm_mode_duplicate(dev, nv_connector->native_mode);
  833. drm_mode_probed_add(connector, mode);
  834. ret = 1;
  835. }
  836. /* Determine LVDS colour depth, must happen after determining
  837. * "native" mode as some VBIOS tables require us to use the
  838. * pixel clock as part of the lookup...
  839. */
  840. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
  841. nouveau_connector_detect_depth(connector);
  842. if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
  843. ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
  844. if (nv_connector->type == DCB_CONNECTOR_LVDS ||
  845. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
  846. nv_connector->type == DCB_CONNECTOR_eDP)
  847. ret += nouveau_connector_scaler_modes_add(connector);
  848. return ret;
  849. }
  850. static unsigned
  851. get_tmds_link_bandwidth(struct drm_connector *connector, bool hdmi)
  852. {
  853. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  854. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  855. struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
  856. if (hdmi) {
  857. if (nouveau_hdmimhz > 0)
  858. return nouveau_hdmimhz * 1000;
  859. /* Note: these limits are conservative, some Fermi's
  860. * can do 297 MHz. Unclear how this can be determined.
  861. */
  862. if (drm->device.info.family >= NV_DEVICE_INFO_V0_KEPLER)
  863. return 297000;
  864. if (drm->device.info.family >= NV_DEVICE_INFO_V0_FERMI)
  865. return 225000;
  866. }
  867. if (dcb->location != DCB_LOC_ON_CHIP ||
  868. drm->device.info.chipset >= 0x46)
  869. return 165000;
  870. else if (drm->device.info.chipset >= 0x40)
  871. return 155000;
  872. else if (drm->device.info.chipset >= 0x18)
  873. return 135000;
  874. else
  875. return 112000;
  876. }
  877. static int
  878. nouveau_connector_mode_valid(struct drm_connector *connector,
  879. struct drm_display_mode *mode)
  880. {
  881. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  882. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  883. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  884. unsigned min_clock = 25000, max_clock = min_clock;
  885. unsigned clock = mode->clock;
  886. bool hdmi;
  887. switch (nv_encoder->dcb->type) {
  888. case DCB_OUTPUT_LVDS:
  889. if (nv_connector->native_mode &&
  890. (mode->hdisplay > nv_connector->native_mode->hdisplay ||
  891. mode->vdisplay > nv_connector->native_mode->vdisplay))
  892. return MODE_PANEL;
  893. min_clock = 0;
  894. max_clock = 400000;
  895. break;
  896. case DCB_OUTPUT_TMDS:
  897. hdmi = drm_detect_hdmi_monitor(nv_connector->edid);
  898. max_clock = get_tmds_link_bandwidth(connector, hdmi);
  899. if (!hdmi && nouveau_duallink &&
  900. nv_encoder->dcb->duallink_possible)
  901. max_clock *= 2;
  902. break;
  903. case DCB_OUTPUT_ANALOG:
  904. max_clock = nv_encoder->dcb->crtconf.maxfreq;
  905. if (!max_clock)
  906. max_clock = 350000;
  907. break;
  908. case DCB_OUTPUT_TV:
  909. return get_slave_funcs(encoder)->mode_valid(encoder, mode);
  910. case DCB_OUTPUT_DP:
  911. max_clock = nv_encoder->dp.link_nr;
  912. max_clock *= nv_encoder->dp.link_bw;
  913. clock = clock * (connector->display_info.bpc * 3) / 10;
  914. break;
  915. default:
  916. BUG_ON(1);
  917. return MODE_BAD;
  918. }
  919. if (clock < min_clock)
  920. return MODE_CLOCK_LOW;
  921. if (clock > max_clock)
  922. return MODE_CLOCK_HIGH;
  923. return MODE_OK;
  924. }
  925. static struct drm_encoder *
  926. nouveau_connector_best_encoder(struct drm_connector *connector)
  927. {
  928. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  929. if (nv_connector->detected_encoder)
  930. return to_drm_encoder(nv_connector->detected_encoder);
  931. return NULL;
  932. }
  933. static const struct drm_connector_helper_funcs
  934. nouveau_connector_helper_funcs = {
  935. .get_modes = nouveau_connector_get_modes,
  936. .mode_valid = nouveau_connector_mode_valid,
  937. .best_encoder = nouveau_connector_best_encoder,
  938. };
  939. static int
  940. nouveau_connector_dpms(struct drm_connector *connector, int mode)
  941. {
  942. if (drm_drv_uses_atomic_modeset(connector->dev))
  943. return drm_atomic_helper_connector_dpms(connector, mode);
  944. return drm_helper_connector_dpms(connector, mode);
  945. }
  946. static const struct drm_connector_funcs
  947. nouveau_connector_funcs = {
  948. .dpms = nouveau_connector_dpms,
  949. .reset = nouveau_conn_reset,
  950. .detect = nouveau_connector_detect,
  951. .force = nouveau_connector_force,
  952. .fill_modes = drm_helper_probe_single_connector_modes,
  953. .set_property = nouveau_connector_set_property,
  954. .destroy = nouveau_connector_destroy,
  955. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  956. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  957. .atomic_set_property = nouveau_conn_atomic_set_property,
  958. .atomic_get_property = nouveau_conn_atomic_get_property,
  959. };
  960. static const struct drm_connector_funcs
  961. nouveau_connector_funcs_lvds = {
  962. .dpms = nouveau_connector_dpms,
  963. .reset = nouveau_conn_reset,
  964. .detect = nouveau_connector_detect_lvds,
  965. .force = nouveau_connector_force,
  966. .fill_modes = drm_helper_probe_single_connector_modes,
  967. .set_property = nouveau_connector_set_property,
  968. .destroy = nouveau_connector_destroy,
  969. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  970. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  971. .atomic_set_property = nouveau_conn_atomic_set_property,
  972. .atomic_get_property = nouveau_conn_atomic_get_property,
  973. };
  974. static int
  975. nouveau_connector_hotplug(struct nvif_notify *notify)
  976. {
  977. struct nouveau_connector *nv_connector =
  978. container_of(notify, typeof(*nv_connector), hpd);
  979. struct drm_connector *connector = &nv_connector->base;
  980. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  981. const struct nvif_notify_conn_rep_v0 *rep = notify->data;
  982. const char *name = connector->name;
  983. struct nouveau_encoder *nv_encoder;
  984. if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
  985. NV_DEBUG(drm, "service %s\n", name);
  986. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP)))
  987. nv50_mstm_service(nv_encoder->dp.mstm);
  988. } else {
  989. bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG);
  990. NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
  991. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP))) {
  992. if (!plugged)
  993. nv50_mstm_remove(nv_encoder->dp.mstm);
  994. }
  995. drm_helper_hpd_irq_event(connector->dev);
  996. }
  997. return NVIF_NOTIFY_KEEP;
  998. }
  999. static ssize_t
  1000. nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg)
  1001. {
  1002. struct nouveau_connector *nv_connector =
  1003. container_of(obj, typeof(*nv_connector), aux);
  1004. struct nouveau_encoder *nv_encoder;
  1005. struct nvkm_i2c_aux *aux;
  1006. int ret;
  1007. nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
  1008. if (!nv_encoder || !(aux = nv_encoder->aux))
  1009. return -ENODEV;
  1010. if (WARN_ON(msg->size > 16))
  1011. return -E2BIG;
  1012. if (msg->size == 0)
  1013. return msg->size;
  1014. ret = nvkm_i2c_aux_acquire(aux);
  1015. if (ret)
  1016. return ret;
  1017. ret = nvkm_i2c_aux_xfer(aux, false, msg->request, msg->address,
  1018. msg->buffer, msg->size);
  1019. nvkm_i2c_aux_release(aux);
  1020. if (ret >= 0) {
  1021. msg->reply = ret;
  1022. return msg->size;
  1023. }
  1024. return ret;
  1025. }
  1026. static int
  1027. drm_conntype_from_dcb(enum dcb_connector_type dcb)
  1028. {
  1029. switch (dcb) {
  1030. case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA;
  1031. case DCB_CONNECTOR_TV_0 :
  1032. case DCB_CONNECTOR_TV_1 :
  1033. case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV;
  1034. case DCB_CONNECTOR_DMS59_0 :
  1035. case DCB_CONNECTOR_DMS59_1 :
  1036. case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII;
  1037. case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID;
  1038. case DCB_CONNECTOR_LVDS :
  1039. case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
  1040. case DCB_CONNECTOR_DMS59_DP0:
  1041. case DCB_CONNECTOR_DMS59_DP1:
  1042. case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort;
  1043. case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP;
  1044. case DCB_CONNECTOR_HDMI_0 :
  1045. case DCB_CONNECTOR_HDMI_1 :
  1046. case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA;
  1047. default:
  1048. break;
  1049. }
  1050. return DRM_MODE_CONNECTOR_Unknown;
  1051. }
  1052. struct drm_connector *
  1053. nouveau_connector_create(struct drm_device *dev, int index)
  1054. {
  1055. const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
  1056. struct nouveau_drm *drm = nouveau_drm(dev);
  1057. struct nouveau_display *disp = nouveau_display(dev);
  1058. struct nouveau_connector *nv_connector = NULL;
  1059. struct drm_connector *connector;
  1060. int type, ret = 0;
  1061. bool dummy;
  1062. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1063. nv_connector = nouveau_connector(connector);
  1064. if (nv_connector->index == index)
  1065. return connector;
  1066. }
  1067. nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
  1068. if (!nv_connector)
  1069. return ERR_PTR(-ENOMEM);
  1070. connector = &nv_connector->base;
  1071. nv_connector->index = index;
  1072. /* attempt to parse vbios connector type and hotplug gpio */
  1073. nv_connector->dcb = olddcb_conn(dev, index);
  1074. if (nv_connector->dcb) {
  1075. u32 entry = ROM16(nv_connector->dcb[0]);
  1076. if (olddcb_conntab(dev)[3] >= 4)
  1077. entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
  1078. nv_connector->type = nv_connector->dcb[0];
  1079. if (drm_conntype_from_dcb(nv_connector->type) ==
  1080. DRM_MODE_CONNECTOR_Unknown) {
  1081. NV_WARN(drm, "unknown connector type %02x\n",
  1082. nv_connector->type);
  1083. nv_connector->type = DCB_CONNECTOR_NONE;
  1084. }
  1085. /* Gigabyte NX85T */
  1086. if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
  1087. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  1088. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1089. }
  1090. /* Gigabyte GV-NX86T512H */
  1091. if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
  1092. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  1093. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1094. }
  1095. } else {
  1096. nv_connector->type = DCB_CONNECTOR_NONE;
  1097. }
  1098. /* no vbios data, or an unknown dcb connector type - attempt to
  1099. * figure out something suitable ourselves
  1100. */
  1101. if (nv_connector->type == DCB_CONNECTOR_NONE) {
  1102. struct nouveau_drm *drm = nouveau_drm(dev);
  1103. struct dcb_table *dcbt = &drm->vbios.dcb;
  1104. u32 encoders = 0;
  1105. int i;
  1106. for (i = 0; i < dcbt->entries; i++) {
  1107. if (dcbt->entry[i].connector == nv_connector->index)
  1108. encoders |= (1 << dcbt->entry[i].type);
  1109. }
  1110. if (encoders & (1 << DCB_OUTPUT_DP)) {
  1111. if (encoders & (1 << DCB_OUTPUT_TMDS))
  1112. nv_connector->type = DCB_CONNECTOR_DP;
  1113. else
  1114. nv_connector->type = DCB_CONNECTOR_eDP;
  1115. } else
  1116. if (encoders & (1 << DCB_OUTPUT_TMDS)) {
  1117. if (encoders & (1 << DCB_OUTPUT_ANALOG))
  1118. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1119. else
  1120. nv_connector->type = DCB_CONNECTOR_DVI_D;
  1121. } else
  1122. if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
  1123. nv_connector->type = DCB_CONNECTOR_VGA;
  1124. } else
  1125. if (encoders & (1 << DCB_OUTPUT_LVDS)) {
  1126. nv_connector->type = DCB_CONNECTOR_LVDS;
  1127. } else
  1128. if (encoders & (1 << DCB_OUTPUT_TV)) {
  1129. nv_connector->type = DCB_CONNECTOR_TV_0;
  1130. }
  1131. }
  1132. switch ((type = drm_conntype_from_dcb(nv_connector->type))) {
  1133. case DRM_MODE_CONNECTOR_LVDS:
  1134. ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
  1135. if (ret) {
  1136. NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
  1137. kfree(nv_connector);
  1138. return ERR_PTR(ret);
  1139. }
  1140. funcs = &nouveau_connector_funcs_lvds;
  1141. break;
  1142. case DRM_MODE_CONNECTOR_DisplayPort:
  1143. case DRM_MODE_CONNECTOR_eDP:
  1144. nv_connector->aux.dev = dev->dev;
  1145. nv_connector->aux.transfer = nouveau_connector_aux_xfer;
  1146. ret = drm_dp_aux_register(&nv_connector->aux);
  1147. if (ret) {
  1148. NV_ERROR(drm, "failed to register aux channel\n");
  1149. kfree(nv_connector);
  1150. return ERR_PTR(ret);
  1151. }
  1152. funcs = &nouveau_connector_funcs;
  1153. break;
  1154. default:
  1155. funcs = &nouveau_connector_funcs;
  1156. break;
  1157. }
  1158. /* defaults, will get overridden in detect() */
  1159. connector->interlace_allowed = false;
  1160. connector->doublescan_allowed = false;
  1161. drm_connector_init(dev, connector, funcs, type);
  1162. drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
  1163. connector->funcs->reset(connector);
  1164. nouveau_conn_attach_properties(connector);
  1165. /* Default scaling mode */
  1166. switch (nv_connector->type) {
  1167. case DCB_CONNECTOR_LVDS:
  1168. case DCB_CONNECTOR_LVDS_SPWG:
  1169. case DCB_CONNECTOR_eDP:
  1170. /* see note in nouveau_connector_set_property() */
  1171. if (disp->disp.oclass < NV50_DISP) {
  1172. nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
  1173. break;
  1174. }
  1175. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1176. break;
  1177. default:
  1178. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1179. break;
  1180. }
  1181. /* dithering properties */
  1182. switch (nv_connector->type) {
  1183. case DCB_CONNECTOR_TV_0:
  1184. case DCB_CONNECTOR_TV_1:
  1185. case DCB_CONNECTOR_TV_3:
  1186. case DCB_CONNECTOR_VGA:
  1187. break;
  1188. default:
  1189. nv_connector->dithering_mode = DITHERING_MODE_AUTO;
  1190. break;
  1191. }
  1192. ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true,
  1193. NV04_DISP_NTFY_CONN,
  1194. &(struct nvif_notify_conn_req_v0) {
  1195. .mask = NVIF_NOTIFY_CONN_V0_ANY,
  1196. .conn = index,
  1197. },
  1198. sizeof(struct nvif_notify_conn_req_v0),
  1199. sizeof(struct nvif_notify_conn_rep_v0),
  1200. &nv_connector->hpd);
  1201. if (ret)
  1202. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  1203. else
  1204. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1205. drm_connector_register(connector);
  1206. return connector;
  1207. }