nouveau_connector.c 42 KB

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