nouveau_connector.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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, NULL, 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->client.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, NULL, 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->client.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->client.device.info.family == NV_DEVICE_INFO_V0_KELVIN ||
  475. (drm->client.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. /* Outputs are only polled while runtime active, so acquiring a
  510. * runtime PM ref here is unnecessary (and would deadlock upon
  511. * runtime suspend because it waits for polling to finish).
  512. */
  513. if (!drm_kms_helper_is_poll_worker()) {
  514. ret = pm_runtime_get_sync(connector->dev->dev);
  515. if (ret < 0 && ret != -EACCES)
  516. return conn_status;
  517. }
  518. nv_encoder = nouveau_connector_ddc_detect(connector);
  519. if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
  520. if ((vga_switcheroo_handler_flags() &
  521. VGA_SWITCHEROO_CAN_SWITCH_DDC) &&
  522. nv_connector->type == DCB_CONNECTOR_LVDS)
  523. nv_connector->edid = drm_get_edid_switcheroo(connector,
  524. i2c);
  525. else
  526. nv_connector->edid = drm_get_edid(connector, i2c);
  527. drm_mode_connector_update_edid_property(connector,
  528. nv_connector->edid);
  529. if (!nv_connector->edid) {
  530. NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
  531. connector->name);
  532. goto detect_analog;
  533. }
  534. /* Override encoder type for DVI-I based on whether EDID
  535. * says the display is digital or analog, both use the
  536. * same i2c channel so the value returned from ddc_detect
  537. * isn't necessarily correct.
  538. */
  539. nv_partner = NULL;
  540. if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
  541. nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
  542. if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
  543. nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
  544. if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
  545. nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
  546. (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
  547. nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
  548. if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
  549. type = DCB_OUTPUT_TMDS;
  550. else
  551. type = DCB_OUTPUT_ANALOG;
  552. nv_encoder = find_encoder(connector, type);
  553. }
  554. nouveau_connector_set_encoder(connector, nv_encoder);
  555. conn_status = connector_status_connected;
  556. goto out;
  557. }
  558. nv_encoder = nouveau_connector_of_detect(connector);
  559. if (nv_encoder) {
  560. nouveau_connector_set_encoder(connector, nv_encoder);
  561. conn_status = connector_status_connected;
  562. goto out;
  563. }
  564. detect_analog:
  565. nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
  566. if (!nv_encoder && !nouveau_tv_disable)
  567. nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
  568. if (nv_encoder && force) {
  569. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  570. const struct drm_encoder_helper_funcs *helper =
  571. encoder->helper_private;
  572. if (helper->detect(encoder, connector) ==
  573. connector_status_connected) {
  574. nouveau_connector_set_encoder(connector, nv_encoder);
  575. conn_status = connector_status_connected;
  576. goto out;
  577. }
  578. }
  579. out:
  580. if (!drm_kms_helper_is_poll_worker()) {
  581. pm_runtime_mark_last_busy(connector->dev->dev);
  582. pm_runtime_put_autosuspend(connector->dev->dev);
  583. }
  584. return conn_status;
  585. }
  586. static enum drm_connector_status
  587. nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
  588. {
  589. struct drm_device *dev = connector->dev;
  590. struct nouveau_drm *drm = nouveau_drm(dev);
  591. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  592. struct nouveau_encoder *nv_encoder = NULL;
  593. enum drm_connector_status status = connector_status_disconnected;
  594. /* Cleanup the previous EDID block. */
  595. if (nv_connector->edid) {
  596. drm_mode_connector_update_edid_property(connector, NULL);
  597. kfree(nv_connector->edid);
  598. nv_connector->edid = NULL;
  599. }
  600. nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
  601. if (!nv_encoder)
  602. return connector_status_disconnected;
  603. /* Try retrieving EDID via DDC */
  604. if (!drm->vbios.fp_no_ddc) {
  605. status = nouveau_connector_detect(connector, force);
  606. if (status == connector_status_connected)
  607. goto out;
  608. }
  609. /* On some laptops (Sony, i'm looking at you) there appears to
  610. * be no direct way of accessing the panel's EDID. The only
  611. * option available to us appears to be to ask ACPI for help..
  612. *
  613. * It's important this check's before trying straps, one of the
  614. * said manufacturer's laptops are configured in such a way
  615. * the nouveau decides an entry in the VBIOS FP mode table is
  616. * valid - it's not (rh#613284)
  617. */
  618. if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
  619. if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
  620. status = connector_status_connected;
  621. goto out;
  622. }
  623. }
  624. /* If no EDID found above, and the VBIOS indicates a hardcoded
  625. * modeline is avalilable for the panel, set it as the panel's
  626. * native mode and exit.
  627. */
  628. if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
  629. nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
  630. status = connector_status_connected;
  631. goto out;
  632. }
  633. /* Still nothing, some VBIOS images have a hardcoded EDID block
  634. * stored for the panel stored in them.
  635. */
  636. if (!drm->vbios.fp_no_ddc) {
  637. struct edid *edid =
  638. (struct edid *)nouveau_bios_embedded_edid(dev);
  639. if (edid) {
  640. nv_connector->edid =
  641. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  642. if (nv_connector->edid)
  643. status = connector_status_connected;
  644. }
  645. }
  646. out:
  647. #if defined(CONFIG_ACPI_BUTTON) || \
  648. (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
  649. if (status == connector_status_connected &&
  650. !nouveau_ignorelid && !acpi_lid_open())
  651. status = connector_status_unknown;
  652. #endif
  653. drm_mode_connector_update_edid_property(connector, nv_connector->edid);
  654. nouveau_connector_set_encoder(connector, nv_encoder);
  655. return status;
  656. }
  657. static void
  658. nouveau_connector_force(struct drm_connector *connector)
  659. {
  660. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  661. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  662. struct nouveau_encoder *nv_encoder;
  663. int type;
  664. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  665. if (connector->force == DRM_FORCE_ON_DIGITAL)
  666. type = DCB_OUTPUT_TMDS;
  667. else
  668. type = DCB_OUTPUT_ANALOG;
  669. } else
  670. type = DCB_OUTPUT_ANY;
  671. nv_encoder = find_encoder(connector, type);
  672. if (!nv_encoder) {
  673. NV_ERROR(drm, "can't find encoder to force %s on!\n",
  674. connector->name);
  675. connector->status = connector_status_disconnected;
  676. return;
  677. }
  678. nouveau_connector_set_encoder(connector, nv_encoder);
  679. }
  680. static int
  681. nouveau_connector_set_property(struct drm_connector *connector,
  682. struct drm_property *property, uint64_t value)
  683. {
  684. struct nouveau_conn_atom *asyc = nouveau_conn_atom(connector->state);
  685. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  686. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  687. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  688. int ret;
  689. ret = connector->funcs->atomic_set_property(&nv_connector->base,
  690. &asyc->state,
  691. property, value);
  692. if (ret) {
  693. if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
  694. return get_slave_funcs(encoder)->set_property(
  695. encoder, connector, property, value);
  696. return ret;
  697. }
  698. nv_connector->scaling_mode = asyc->scaler.mode;
  699. nv_connector->dithering_mode = asyc->dither.mode;
  700. if (connector->encoder && connector->encoder->crtc) {
  701. ret = drm_crtc_helper_set_mode(connector->encoder->crtc,
  702. &connector->encoder->crtc->mode,
  703. connector->encoder->crtc->x,
  704. connector->encoder->crtc->y,
  705. NULL);
  706. if (!ret)
  707. return -EINVAL;
  708. }
  709. return 0;
  710. }
  711. struct moderec {
  712. int hdisplay;
  713. int vdisplay;
  714. };
  715. static struct moderec scaler_modes[] = {
  716. { 1920, 1200 },
  717. { 1920, 1080 },
  718. { 1680, 1050 },
  719. { 1600, 1200 },
  720. { 1400, 1050 },
  721. { 1280, 1024 },
  722. { 1280, 960 },
  723. { 1152, 864 },
  724. { 1024, 768 },
  725. { 800, 600 },
  726. { 720, 400 },
  727. { 640, 480 },
  728. { 640, 400 },
  729. { 640, 350 },
  730. {}
  731. };
  732. static int
  733. nouveau_connector_scaler_modes_add(struct drm_connector *connector)
  734. {
  735. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  736. struct drm_display_mode *native = nv_connector->native_mode, *m;
  737. struct drm_device *dev = connector->dev;
  738. struct moderec *mode = &scaler_modes[0];
  739. int modes = 0;
  740. if (!native)
  741. return 0;
  742. while (mode->hdisplay) {
  743. if (mode->hdisplay <= native->hdisplay &&
  744. mode->vdisplay <= native->vdisplay &&
  745. (mode->hdisplay != native->hdisplay ||
  746. mode->vdisplay != native->vdisplay)) {
  747. m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
  748. drm_mode_vrefresh(native), false,
  749. false, false);
  750. if (!m)
  751. continue;
  752. drm_mode_probed_add(connector, m);
  753. modes++;
  754. }
  755. mode++;
  756. }
  757. return modes;
  758. }
  759. static void
  760. nouveau_connector_detect_depth(struct drm_connector *connector)
  761. {
  762. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  763. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  764. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  765. struct nvbios *bios = &drm->vbios;
  766. struct drm_display_mode *mode = nv_connector->native_mode;
  767. bool duallink;
  768. /* if the edid is feeling nice enough to provide this info, use it */
  769. if (nv_connector->edid && connector->display_info.bpc)
  770. return;
  771. /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
  772. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  773. connector->display_info.bpc = 6;
  774. return;
  775. }
  776. /* we're out of options unless we're LVDS, default to 8bpc */
  777. if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
  778. connector->display_info.bpc = 8;
  779. return;
  780. }
  781. connector->display_info.bpc = 6;
  782. /* LVDS: panel straps */
  783. if (bios->fp_no_ddc) {
  784. if (bios->fp.if_is_24bit)
  785. connector->display_info.bpc = 8;
  786. return;
  787. }
  788. /* LVDS: DDC panel, need to first determine the number of links to
  789. * know which if_is_24bit flag to check...
  790. */
  791. if (nv_connector->edid &&
  792. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
  793. duallink = ((u8 *)nv_connector->edid)[121] == 2;
  794. else
  795. duallink = mode->clock >= bios->fp.duallink_transition_clk;
  796. if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
  797. ( duallink && (bios->fp.strapless_is_24bit & 2)))
  798. connector->display_info.bpc = 8;
  799. }
  800. static int
  801. nouveau_connector_get_modes(struct drm_connector *connector)
  802. {
  803. struct drm_device *dev = connector->dev;
  804. struct nouveau_drm *drm = nouveau_drm(dev);
  805. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  806. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  807. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  808. int ret = 0;
  809. /* destroy the native mode, the attached monitor could have changed.
  810. */
  811. if (nv_connector->native_mode) {
  812. drm_mode_destroy(dev, nv_connector->native_mode);
  813. nv_connector->native_mode = NULL;
  814. }
  815. if (nv_connector->edid)
  816. ret = drm_add_edid_modes(connector, nv_connector->edid);
  817. else
  818. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
  819. (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
  820. drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
  821. struct drm_display_mode mode;
  822. nouveau_bios_fp_mode(dev, &mode);
  823. nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
  824. }
  825. /* Determine display colour depth for everything except LVDS now,
  826. * DP requires this before mode_valid() is called.
  827. */
  828. if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
  829. nouveau_connector_detect_depth(connector);
  830. /* Find the native mode if this is a digital panel, if we didn't
  831. * find any modes through DDC previously add the native mode to
  832. * the list of modes.
  833. */
  834. if (!nv_connector->native_mode)
  835. nv_connector->native_mode = nouveau_conn_native_mode(connector);
  836. if (ret == 0 && nv_connector->native_mode) {
  837. struct drm_display_mode *mode;
  838. mode = drm_mode_duplicate(dev, nv_connector->native_mode);
  839. drm_mode_probed_add(connector, mode);
  840. ret = 1;
  841. }
  842. /* Determine LVDS colour depth, must happen after determining
  843. * "native" mode as some VBIOS tables require us to use the
  844. * pixel clock as part of the lookup...
  845. */
  846. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
  847. nouveau_connector_detect_depth(connector);
  848. if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
  849. ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
  850. if (nv_connector->type == DCB_CONNECTOR_LVDS ||
  851. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
  852. nv_connector->type == DCB_CONNECTOR_eDP)
  853. ret += nouveau_connector_scaler_modes_add(connector);
  854. return ret;
  855. }
  856. static unsigned
  857. get_tmds_link_bandwidth(struct drm_connector *connector, bool hdmi)
  858. {
  859. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  860. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  861. struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
  862. if (hdmi) {
  863. if (nouveau_hdmimhz > 0)
  864. return nouveau_hdmimhz * 1000;
  865. /* Note: these limits are conservative, some Fermi's
  866. * can do 297 MHz. Unclear how this can be determined.
  867. */
  868. if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_KEPLER)
  869. return 297000;
  870. if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_FERMI)
  871. return 225000;
  872. }
  873. if (dcb->location != DCB_LOC_ON_CHIP ||
  874. drm->client.device.info.chipset >= 0x46)
  875. return 165000;
  876. else if (drm->client.device.info.chipset >= 0x40)
  877. return 155000;
  878. else if (drm->client.device.info.chipset >= 0x18)
  879. return 135000;
  880. else
  881. return 112000;
  882. }
  883. static int
  884. nouveau_connector_mode_valid(struct drm_connector *connector,
  885. struct drm_display_mode *mode)
  886. {
  887. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  888. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  889. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  890. unsigned min_clock = 25000, max_clock = min_clock;
  891. unsigned clock = mode->clock;
  892. bool hdmi;
  893. switch (nv_encoder->dcb->type) {
  894. case DCB_OUTPUT_LVDS:
  895. if (nv_connector->native_mode &&
  896. (mode->hdisplay > nv_connector->native_mode->hdisplay ||
  897. mode->vdisplay > nv_connector->native_mode->vdisplay))
  898. return MODE_PANEL;
  899. min_clock = 0;
  900. max_clock = 400000;
  901. break;
  902. case DCB_OUTPUT_TMDS:
  903. hdmi = drm_detect_hdmi_monitor(nv_connector->edid);
  904. max_clock = get_tmds_link_bandwidth(connector, hdmi);
  905. if (!hdmi && nouveau_duallink &&
  906. nv_encoder->dcb->duallink_possible)
  907. max_clock *= 2;
  908. break;
  909. case DCB_OUTPUT_ANALOG:
  910. max_clock = nv_encoder->dcb->crtconf.maxfreq;
  911. if (!max_clock)
  912. max_clock = 350000;
  913. break;
  914. case DCB_OUTPUT_TV:
  915. return get_slave_funcs(encoder)->mode_valid(encoder, mode);
  916. case DCB_OUTPUT_DP:
  917. max_clock = nv_encoder->dp.link_nr;
  918. max_clock *= nv_encoder->dp.link_bw;
  919. clock = clock * (connector->display_info.bpc * 3) / 10;
  920. break;
  921. default:
  922. BUG();
  923. return MODE_BAD;
  924. }
  925. if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
  926. clock *= 2;
  927. if (clock < min_clock)
  928. return MODE_CLOCK_LOW;
  929. if (clock > max_clock)
  930. return MODE_CLOCK_HIGH;
  931. return MODE_OK;
  932. }
  933. static struct drm_encoder *
  934. nouveau_connector_best_encoder(struct drm_connector *connector)
  935. {
  936. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  937. if (nv_connector->detected_encoder)
  938. return to_drm_encoder(nv_connector->detected_encoder);
  939. return NULL;
  940. }
  941. static const struct drm_connector_helper_funcs
  942. nouveau_connector_helper_funcs = {
  943. .get_modes = nouveau_connector_get_modes,
  944. .mode_valid = nouveau_connector_mode_valid,
  945. .best_encoder = nouveau_connector_best_encoder,
  946. };
  947. static const struct drm_connector_funcs
  948. nouveau_connector_funcs = {
  949. .dpms = drm_helper_connector_dpms,
  950. .reset = nouveau_conn_reset,
  951. .detect = nouveau_connector_detect,
  952. .force = nouveau_connector_force,
  953. .fill_modes = drm_helper_probe_single_connector_modes,
  954. .set_property = nouveau_connector_set_property,
  955. .destroy = nouveau_connector_destroy,
  956. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  957. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  958. .atomic_set_property = nouveau_conn_atomic_set_property,
  959. .atomic_get_property = nouveau_conn_atomic_get_property,
  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. };
  975. static int
  976. nouveau_connector_hotplug(struct nvif_notify *notify)
  977. {
  978. struct nouveau_connector *nv_connector =
  979. container_of(notify, typeof(*nv_connector), hpd);
  980. struct drm_connector *connector = &nv_connector->base;
  981. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  982. const struct nvif_notify_conn_rep_v0 *rep = notify->data;
  983. const char *name = connector->name;
  984. struct nouveau_encoder *nv_encoder;
  985. if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
  986. NV_DEBUG(drm, "service %s\n", name);
  987. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP)))
  988. nv50_mstm_service(nv_encoder->dp.mstm);
  989. } else {
  990. bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG);
  991. NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
  992. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP))) {
  993. if (!plugged)
  994. nv50_mstm_remove(nv_encoder->dp.mstm);
  995. }
  996. drm_helper_hpd_irq_event(connector->dev);
  997. }
  998. return NVIF_NOTIFY_KEEP;
  999. }
  1000. static ssize_t
  1001. nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg)
  1002. {
  1003. struct nouveau_connector *nv_connector =
  1004. container_of(obj, typeof(*nv_connector), aux);
  1005. struct nouveau_encoder *nv_encoder;
  1006. struct nvkm_i2c_aux *aux;
  1007. u8 size = msg->size;
  1008. int ret;
  1009. nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
  1010. if (!nv_encoder || !(aux = nv_encoder->aux))
  1011. return -ENODEV;
  1012. if (WARN_ON(msg->size > 16))
  1013. return -E2BIG;
  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, &size);
  1019. nvkm_i2c_aux_release(aux);
  1020. if (ret >= 0) {
  1021. msg->reply = ret;
  1022. return 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. case DCB_CONNECTOR_WFD : return DRM_MODE_CONNECTOR_VIRTUAL;
  1048. default:
  1049. break;
  1050. }
  1051. return DRM_MODE_CONNECTOR_Unknown;
  1052. }
  1053. struct drm_connector *
  1054. nouveau_connector_create(struct drm_device *dev, int index)
  1055. {
  1056. const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
  1057. struct nouveau_drm *drm = nouveau_drm(dev);
  1058. struct nouveau_display *disp = nouveau_display(dev);
  1059. struct nouveau_connector *nv_connector = NULL;
  1060. struct drm_connector *connector;
  1061. int type, ret = 0;
  1062. bool dummy;
  1063. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1064. nv_connector = nouveau_connector(connector);
  1065. if (nv_connector->index == index)
  1066. return connector;
  1067. }
  1068. nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
  1069. if (!nv_connector)
  1070. return ERR_PTR(-ENOMEM);
  1071. connector = &nv_connector->base;
  1072. nv_connector->index = index;
  1073. /* attempt to parse vbios connector type and hotplug gpio */
  1074. nv_connector->dcb = olddcb_conn(dev, index);
  1075. if (nv_connector->dcb) {
  1076. u32 entry = ROM16(nv_connector->dcb[0]);
  1077. if (olddcb_conntab(dev)[3] >= 4)
  1078. entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
  1079. nv_connector->type = nv_connector->dcb[0];
  1080. if (drm_conntype_from_dcb(nv_connector->type) ==
  1081. DRM_MODE_CONNECTOR_Unknown) {
  1082. NV_WARN(drm, "unknown connector type %02x\n",
  1083. nv_connector->type);
  1084. nv_connector->type = DCB_CONNECTOR_NONE;
  1085. }
  1086. /* Gigabyte NX85T */
  1087. if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
  1088. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  1089. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1090. }
  1091. /* Gigabyte GV-NX86T512H */
  1092. if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
  1093. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  1094. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1095. }
  1096. } else {
  1097. nv_connector->type = DCB_CONNECTOR_NONE;
  1098. }
  1099. /* no vbios data, or an unknown dcb connector type - attempt to
  1100. * figure out something suitable ourselves
  1101. */
  1102. if (nv_connector->type == DCB_CONNECTOR_NONE) {
  1103. struct nouveau_drm *drm = nouveau_drm(dev);
  1104. struct dcb_table *dcbt = &drm->vbios.dcb;
  1105. u32 encoders = 0;
  1106. int i;
  1107. for (i = 0; i < dcbt->entries; i++) {
  1108. if (dcbt->entry[i].connector == nv_connector->index)
  1109. encoders |= (1 << dcbt->entry[i].type);
  1110. }
  1111. if (encoders & (1 << DCB_OUTPUT_DP)) {
  1112. if (encoders & (1 << DCB_OUTPUT_TMDS))
  1113. nv_connector->type = DCB_CONNECTOR_DP;
  1114. else
  1115. nv_connector->type = DCB_CONNECTOR_eDP;
  1116. } else
  1117. if (encoders & (1 << DCB_OUTPUT_TMDS)) {
  1118. if (encoders & (1 << DCB_OUTPUT_ANALOG))
  1119. nv_connector->type = DCB_CONNECTOR_DVI_I;
  1120. else
  1121. nv_connector->type = DCB_CONNECTOR_DVI_D;
  1122. } else
  1123. if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
  1124. nv_connector->type = DCB_CONNECTOR_VGA;
  1125. } else
  1126. if (encoders & (1 << DCB_OUTPUT_LVDS)) {
  1127. nv_connector->type = DCB_CONNECTOR_LVDS;
  1128. } else
  1129. if (encoders & (1 << DCB_OUTPUT_TV)) {
  1130. nv_connector->type = DCB_CONNECTOR_TV_0;
  1131. }
  1132. }
  1133. switch ((type = drm_conntype_from_dcb(nv_connector->type))) {
  1134. case DRM_MODE_CONNECTOR_LVDS:
  1135. ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
  1136. if (ret) {
  1137. NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
  1138. kfree(nv_connector);
  1139. return ERR_PTR(ret);
  1140. }
  1141. funcs = &nouveau_connector_funcs_lvds;
  1142. break;
  1143. case DRM_MODE_CONNECTOR_DisplayPort:
  1144. case DRM_MODE_CONNECTOR_eDP:
  1145. nv_connector->aux.dev = dev->dev;
  1146. nv_connector->aux.transfer = nouveau_connector_aux_xfer;
  1147. ret = drm_dp_aux_register(&nv_connector->aux);
  1148. if (ret) {
  1149. NV_ERROR(drm, "failed to register aux channel\n");
  1150. kfree(nv_connector);
  1151. return ERR_PTR(ret);
  1152. }
  1153. funcs = &nouveau_connector_funcs;
  1154. break;
  1155. default:
  1156. funcs = &nouveau_connector_funcs;
  1157. break;
  1158. }
  1159. /* HDMI 3D support */
  1160. if ((disp->disp.oclass >= G82_DISP)
  1161. && ((type == DRM_MODE_CONNECTOR_DisplayPort)
  1162. || (type == DRM_MODE_CONNECTOR_eDP)
  1163. || (type == DRM_MODE_CONNECTOR_HDMIA)))
  1164. connector->stereo_allowed = true;
  1165. /* defaults, will get overridden in detect() */
  1166. connector->interlace_allowed = false;
  1167. connector->doublescan_allowed = false;
  1168. drm_connector_init(dev, connector, funcs, type);
  1169. drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
  1170. connector->funcs->reset(connector);
  1171. nouveau_conn_attach_properties(connector);
  1172. /* Default scaling mode */
  1173. switch (nv_connector->type) {
  1174. case DCB_CONNECTOR_LVDS:
  1175. case DCB_CONNECTOR_LVDS_SPWG:
  1176. case DCB_CONNECTOR_eDP:
  1177. /* see note in nouveau_connector_set_property() */
  1178. if (disp->disp.oclass < NV50_DISP) {
  1179. nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
  1180. break;
  1181. }
  1182. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1183. break;
  1184. default:
  1185. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1186. break;
  1187. }
  1188. /* dithering properties */
  1189. switch (nv_connector->type) {
  1190. case DCB_CONNECTOR_TV_0:
  1191. case DCB_CONNECTOR_TV_1:
  1192. case DCB_CONNECTOR_TV_3:
  1193. case DCB_CONNECTOR_VGA:
  1194. break;
  1195. default:
  1196. nv_connector->dithering_mode = DITHERING_MODE_AUTO;
  1197. break;
  1198. }
  1199. ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true,
  1200. NV04_DISP_NTFY_CONN,
  1201. &(struct nvif_notify_conn_req_v0) {
  1202. .mask = NVIF_NOTIFY_CONN_V0_ANY,
  1203. .conn = index,
  1204. },
  1205. sizeof(struct nvif_notify_conn_req_v0),
  1206. sizeof(struct nvif_notify_conn_rep_v0),
  1207. &nv_connector->hpd);
  1208. if (ret)
  1209. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  1210. else
  1211. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1212. drm_connector_register(connector);
  1213. return connector;
  1214. }