nouveau_connector.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include <acpi/button.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/vga_switcheroo.h>
  29. #include <drm/drmP.h>
  30. #include <drm/drm_atomic_helper.h>
  31. #include <drm/drm_edid.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/drm_atomic.h>
  34. #include "nouveau_reg.h"
  35. #include "nouveau_drv.h"
  36. #include "dispnv04/hw.h"
  37. #include "nouveau_acpi.h"
  38. #include "nouveau_display.h"
  39. #include "nouveau_connector.h"
  40. #include "nouveau_encoder.h"
  41. #include "nouveau_crtc.h"
  42. #include <nvif/class.h>
  43. #include <nvif/cl0046.h>
  44. #include <nvif/event.h>
  45. struct drm_display_mode *
  46. nouveau_conn_native_mode(struct drm_connector *connector)
  47. {
  48. const struct drm_connector_helper_funcs *helper = connector->helper_private;
  49. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  50. struct drm_device *dev = connector->dev;
  51. struct drm_display_mode *mode, *largest = NULL;
  52. int high_w = 0, high_h = 0, high_v = 0;
  53. list_for_each_entry(mode, &connector->probed_modes, head) {
  54. mode->vrefresh = drm_mode_vrefresh(mode);
  55. if (helper->mode_valid(connector, mode) != MODE_OK ||
  56. (mode->flags & DRM_MODE_FLAG_INTERLACE))
  57. continue;
  58. /* Use preferred mode if there is one.. */
  59. if (mode->type & DRM_MODE_TYPE_PREFERRED) {
  60. NV_DEBUG(drm, "native mode from preferred\n");
  61. return drm_mode_duplicate(dev, mode);
  62. }
  63. /* Otherwise, take the resolution with the largest width, then
  64. * height, then vertical refresh
  65. */
  66. if (mode->hdisplay < high_w)
  67. continue;
  68. if (mode->hdisplay == high_w && mode->vdisplay < high_h)
  69. continue;
  70. if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
  71. mode->vrefresh < high_v)
  72. continue;
  73. high_w = mode->hdisplay;
  74. high_h = mode->vdisplay;
  75. high_v = mode->vrefresh;
  76. largest = mode;
  77. }
  78. NV_DEBUG(drm, "native mode from largest: %dx%d@%d\n",
  79. high_w, high_h, high_v);
  80. return largest ? drm_mode_duplicate(dev, largest) : NULL;
  81. }
  82. int
  83. nouveau_conn_atomic_get_property(struct drm_connector *connector,
  84. const struct drm_connector_state *state,
  85. struct drm_property *property, u64 *val)
  86. {
  87. struct nouveau_conn_atom *asyc = nouveau_conn_atom(state);
  88. struct nouveau_display *disp = nouveau_display(connector->dev);
  89. struct drm_device *dev = connector->dev;
  90. if (property == dev->mode_config.scaling_mode_property)
  91. *val = asyc->scaler.mode;
  92. else if (property == disp->underscan_property)
  93. *val = asyc->scaler.underscan.mode;
  94. else if (property == disp->underscan_hborder_property)
  95. *val = asyc->scaler.underscan.hborder;
  96. else if (property == disp->underscan_vborder_property)
  97. *val = asyc->scaler.underscan.vborder;
  98. else if (property == disp->dithering_mode)
  99. *val = asyc->dither.mode;
  100. else if (property == disp->dithering_depth)
  101. *val = asyc->dither.depth;
  102. else if (property == disp->vibrant_hue_property)
  103. *val = asyc->procamp.vibrant_hue;
  104. else if (property == disp->color_vibrance_property)
  105. *val = asyc->procamp.color_vibrance;
  106. else
  107. return -EINVAL;
  108. return 0;
  109. }
  110. int
  111. nouveau_conn_atomic_set_property(struct drm_connector *connector,
  112. struct drm_connector_state *state,
  113. struct drm_property *property, u64 val)
  114. {
  115. struct drm_device *dev = connector->dev;
  116. struct nouveau_conn_atom *asyc = nouveau_conn_atom(state);
  117. struct nouveau_display *disp = nouveau_display(dev);
  118. if (property == dev->mode_config.scaling_mode_property) {
  119. switch (val) {
  120. case DRM_MODE_SCALE_NONE:
  121. /* We allow 'None' for EDID modes, even on a fixed
  122. * panel (some exist with support for lower refresh
  123. * rates, which people might want to use for power-
  124. * saving purposes).
  125. *
  126. * Non-EDID modes will force the use of GPU scaling
  127. * to the native mode regardless of this setting.
  128. */
  129. switch (connector->connector_type) {
  130. case DRM_MODE_CONNECTOR_LVDS:
  131. case DRM_MODE_CONNECTOR_eDP:
  132. /* ... except prior to G80, where the code
  133. * doesn't support such things.
  134. */
  135. if (disp->disp.oclass < NV50_DISP)
  136. return -EINVAL;
  137. break;
  138. default:
  139. break;
  140. }
  141. case DRM_MODE_SCALE_FULLSCREEN:
  142. case DRM_MODE_SCALE_CENTER:
  143. case DRM_MODE_SCALE_ASPECT:
  144. break;
  145. default:
  146. return -EINVAL;
  147. }
  148. if (asyc->scaler.mode != val) {
  149. asyc->scaler.mode = val;
  150. asyc->set.scaler = true;
  151. }
  152. } else
  153. if (property == disp->underscan_property) {
  154. if (asyc->scaler.underscan.mode != val) {
  155. asyc->scaler.underscan.mode = val;
  156. asyc->set.scaler = true;
  157. }
  158. } else
  159. if (property == disp->underscan_hborder_property) {
  160. if (asyc->scaler.underscan.hborder != val) {
  161. asyc->scaler.underscan.hborder = val;
  162. asyc->set.scaler = true;
  163. }
  164. } else
  165. if (property == disp->underscan_vborder_property) {
  166. if (asyc->scaler.underscan.vborder != val) {
  167. asyc->scaler.underscan.vborder = val;
  168. asyc->set.scaler = true;
  169. }
  170. } else
  171. if (property == disp->dithering_mode) {
  172. if (asyc->dither.mode != val) {
  173. asyc->dither.mode = val;
  174. asyc->set.dither = true;
  175. }
  176. } else
  177. if (property == disp->dithering_depth) {
  178. if (asyc->dither.mode != val) {
  179. asyc->dither.depth = val;
  180. asyc->set.dither = true;
  181. }
  182. } else
  183. if (property == disp->vibrant_hue_property) {
  184. if (asyc->procamp.vibrant_hue != val) {
  185. asyc->procamp.vibrant_hue = val;
  186. asyc->set.procamp = true;
  187. }
  188. } else
  189. if (property == disp->color_vibrance_property) {
  190. if (asyc->procamp.color_vibrance != val) {
  191. asyc->procamp.color_vibrance = val;
  192. asyc->set.procamp = true;
  193. }
  194. } else {
  195. return -EINVAL;
  196. }
  197. return 0;
  198. }
  199. void
  200. nouveau_conn_atomic_destroy_state(struct drm_connector *connector,
  201. struct drm_connector_state *state)
  202. {
  203. struct nouveau_conn_atom *asyc = nouveau_conn_atom(state);
  204. __drm_atomic_helper_connector_destroy_state(&asyc->state);
  205. kfree(asyc);
  206. }
  207. struct drm_connector_state *
  208. nouveau_conn_atomic_duplicate_state(struct drm_connector *connector)
  209. {
  210. struct nouveau_conn_atom *armc = nouveau_conn_atom(connector->state);
  211. struct nouveau_conn_atom *asyc;
  212. if (!(asyc = kmalloc(sizeof(*asyc), GFP_KERNEL)))
  213. return NULL;
  214. __drm_atomic_helper_connector_duplicate_state(connector, &asyc->state);
  215. asyc->dither = armc->dither;
  216. asyc->scaler = armc->scaler;
  217. asyc->procamp = armc->procamp;
  218. asyc->set.mask = 0;
  219. return &asyc->state;
  220. }
  221. void
  222. nouveau_conn_reset(struct drm_connector *connector)
  223. {
  224. struct nouveau_conn_atom *asyc;
  225. if (WARN_ON(!(asyc = kzalloc(sizeof(*asyc), GFP_KERNEL))))
  226. return;
  227. if (connector->state)
  228. __drm_atomic_helper_connector_destroy_state(connector->state);
  229. __drm_atomic_helper_connector_reset(connector, &asyc->state);
  230. asyc->dither.mode = DITHERING_MODE_AUTO;
  231. asyc->dither.depth = DITHERING_DEPTH_AUTO;
  232. asyc->scaler.mode = DRM_MODE_SCALE_NONE;
  233. asyc->scaler.underscan.mode = UNDERSCAN_OFF;
  234. asyc->procamp.color_vibrance = 150;
  235. asyc->procamp.vibrant_hue = 90;
  236. if (nouveau_display(connector->dev)->disp.oclass < NV50_DISP) {
  237. switch (connector->connector_type) {
  238. case DRM_MODE_CONNECTOR_LVDS:
  239. /* See note in nouveau_conn_atomic_set_property(). */
  240. asyc->scaler.mode = DRM_MODE_SCALE_FULLSCREEN;
  241. break;
  242. default:
  243. break;
  244. }
  245. }
  246. }
  247. void
  248. nouveau_conn_attach_properties(struct drm_connector *connector)
  249. {
  250. struct drm_device *dev = connector->dev;
  251. struct nouveau_conn_atom *armc = nouveau_conn_atom(connector->state);
  252. struct nouveau_display *disp = nouveau_display(dev);
  253. /* Init DVI-I specific properties. */
  254. if (connector->connector_type == DRM_MODE_CONNECTOR_DVII)
  255. drm_object_attach_property(&connector->base, dev->mode_config.
  256. dvi_i_subconnector_property, 0);
  257. /* Add overscan compensation options to digital outputs. */
  258. if (disp->underscan_property &&
  259. (connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
  260. connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
  261. connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
  262. connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort)) {
  263. drm_object_attach_property(&connector->base,
  264. disp->underscan_property,
  265. UNDERSCAN_OFF);
  266. drm_object_attach_property(&connector->base,
  267. disp->underscan_hborder_property, 0);
  268. drm_object_attach_property(&connector->base,
  269. disp->underscan_vborder_property, 0);
  270. }
  271. /* Add hue and saturation options. */
  272. if (disp->vibrant_hue_property)
  273. drm_object_attach_property(&connector->base,
  274. disp->vibrant_hue_property,
  275. armc->procamp.vibrant_hue);
  276. if (disp->color_vibrance_property)
  277. drm_object_attach_property(&connector->base,
  278. disp->color_vibrance_property,
  279. armc->procamp.color_vibrance);
  280. /* Scaling mode property. */
  281. switch (connector->connector_type) {
  282. case DRM_MODE_CONNECTOR_TV:
  283. break;
  284. case DRM_MODE_CONNECTOR_VGA:
  285. if (disp->disp.oclass < NV50_DISP)
  286. break; /* Can only scale on DFPs. */
  287. /* Fall-through. */
  288. default:
  289. drm_object_attach_property(&connector->base, dev->mode_config.
  290. scaling_mode_property,
  291. armc->scaler.mode);
  292. break;
  293. }
  294. /* Dithering properties. */
  295. switch (connector->connector_type) {
  296. case DRM_MODE_CONNECTOR_TV:
  297. case DRM_MODE_CONNECTOR_VGA:
  298. break;
  299. default:
  300. if (disp->dithering_mode) {
  301. drm_object_attach_property(&connector->base,
  302. disp->dithering_mode,
  303. armc->dither.mode);
  304. }
  305. if (disp->dithering_depth) {
  306. drm_object_attach_property(&connector->base,
  307. disp->dithering_depth,
  308. armc->dither.depth);
  309. }
  310. break;
  311. }
  312. }
  313. MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
  314. int nouveau_tv_disable = 0;
  315. module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
  316. MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
  317. int nouveau_ignorelid = 0;
  318. module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
  319. MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (default: enabled)");
  320. int nouveau_duallink = 1;
  321. module_param_named(duallink, nouveau_duallink, int, 0400);
  322. MODULE_PARM_DESC(hdmimhz, "Force a maximum HDMI pixel clock (in MHz)");
  323. int nouveau_hdmimhz = 0;
  324. module_param_named(hdmimhz, nouveau_hdmimhz, int, 0400);
  325. struct nouveau_encoder *
  326. find_encoder(struct drm_connector *connector, int type)
  327. {
  328. struct drm_device *dev = connector->dev;
  329. struct nouveau_encoder *nv_encoder;
  330. struct drm_encoder *enc;
  331. int i, id;
  332. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  333. id = connector->encoder_ids[i];
  334. if (!id)
  335. break;
  336. enc = drm_encoder_find(dev, id);
  337. if (!enc)
  338. continue;
  339. nv_encoder = nouveau_encoder(enc);
  340. if (type == DCB_OUTPUT_ANY ||
  341. (nv_encoder->dcb && nv_encoder->dcb->type == type))
  342. return nv_encoder;
  343. }
  344. return NULL;
  345. }
  346. struct nouveau_connector *
  347. nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
  348. {
  349. struct drm_device *dev = to_drm_encoder(encoder)->dev;
  350. struct drm_connector *drm_connector;
  351. list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
  352. if (drm_connector->encoder == to_drm_encoder(encoder))
  353. return nouveau_connector(drm_connector);
  354. }
  355. return NULL;
  356. }
  357. static void
  358. nouveau_connector_destroy(struct drm_connector *connector)
  359. {
  360. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  361. nvif_notify_fini(&nv_connector->hpd);
  362. kfree(nv_connector->edid);
  363. drm_connector_unregister(connector);
  364. drm_connector_cleanup(connector);
  365. if (nv_connector->aux.transfer)
  366. drm_dp_aux_unregister(&nv_connector->aux);
  367. kfree(connector);
  368. }
  369. static struct nouveau_encoder *
  370. nouveau_connector_ddc_detect(struct drm_connector *connector)
  371. {
  372. struct drm_device *dev = connector->dev;
  373. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  374. struct nouveau_drm *drm = nouveau_drm(dev);
  375. struct nvkm_gpio *gpio = nvxx_gpio(&drm->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, 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. ret = pm_runtime_get_sync(connector->dev->dev);
  510. if (ret < 0 && ret != -EACCES)
  511. return conn_status;
  512. nv_encoder = nouveau_connector_ddc_detect(connector);
  513. if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
  514. if ((vga_switcheroo_handler_flags() &
  515. VGA_SWITCHEROO_CAN_SWITCH_DDC) &&
  516. nv_connector->type == DCB_CONNECTOR_LVDS)
  517. nv_connector->edid = drm_get_edid_switcheroo(connector,
  518. i2c);
  519. else
  520. nv_connector->edid = drm_get_edid(connector, i2c);
  521. drm_mode_connector_update_edid_property(connector,
  522. nv_connector->edid);
  523. if (!nv_connector->edid) {
  524. NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
  525. connector->name);
  526. goto detect_analog;
  527. }
  528. /* Override encoder type for DVI-I based on whether EDID
  529. * says the display is digital or analog, both use the
  530. * same i2c channel so the value returned from ddc_detect
  531. * isn't necessarily correct.
  532. */
  533. nv_partner = NULL;
  534. if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
  535. nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
  536. if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
  537. nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
  538. if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
  539. nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
  540. (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
  541. nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
  542. if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
  543. type = DCB_OUTPUT_TMDS;
  544. else
  545. type = DCB_OUTPUT_ANALOG;
  546. nv_encoder = find_encoder(connector, type);
  547. }
  548. nouveau_connector_set_encoder(connector, nv_encoder);
  549. conn_status = connector_status_connected;
  550. goto out;
  551. }
  552. nv_encoder = nouveau_connector_of_detect(connector);
  553. if (nv_encoder) {
  554. nouveau_connector_set_encoder(connector, nv_encoder);
  555. conn_status = connector_status_connected;
  556. goto out;
  557. }
  558. detect_analog:
  559. nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
  560. if (!nv_encoder && !nouveau_tv_disable)
  561. nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
  562. if (nv_encoder && force) {
  563. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  564. const struct drm_encoder_helper_funcs *helper =
  565. encoder->helper_private;
  566. if (helper->detect(encoder, connector) ==
  567. connector_status_connected) {
  568. nouveau_connector_set_encoder(connector, nv_encoder);
  569. conn_status = connector_status_connected;
  570. goto out;
  571. }
  572. }
  573. out:
  574. pm_runtime_mark_last_busy(connector->dev->dev);
  575. pm_runtime_put_autosuspend(connector->dev->dev);
  576. return conn_status;
  577. }
  578. static enum drm_connector_status
  579. nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
  580. {
  581. struct drm_device *dev = connector->dev;
  582. struct nouveau_drm *drm = nouveau_drm(dev);
  583. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  584. struct nouveau_encoder *nv_encoder = NULL;
  585. enum drm_connector_status status = connector_status_disconnected;
  586. /* Cleanup the previous EDID block. */
  587. if (nv_connector->edid) {
  588. drm_mode_connector_update_edid_property(connector, NULL);
  589. kfree(nv_connector->edid);
  590. nv_connector->edid = NULL;
  591. }
  592. nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
  593. if (!nv_encoder)
  594. return connector_status_disconnected;
  595. /* Try retrieving EDID via DDC */
  596. if (!drm->vbios.fp_no_ddc) {
  597. status = nouveau_connector_detect(connector, force);
  598. if (status == connector_status_connected)
  599. goto out;
  600. }
  601. /* On some laptops (Sony, i'm looking at you) there appears to
  602. * be no direct way of accessing the panel's EDID. The only
  603. * option available to us appears to be to ask ACPI for help..
  604. *
  605. * It's important this check's before trying straps, one of the
  606. * said manufacturer's laptops are configured in such a way
  607. * the nouveau decides an entry in the VBIOS FP mode table is
  608. * valid - it's not (rh#613284)
  609. */
  610. if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
  611. if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
  612. status = connector_status_connected;
  613. goto out;
  614. }
  615. }
  616. /* If no EDID found above, and the VBIOS indicates a hardcoded
  617. * modeline is avalilable for the panel, set it as the panel's
  618. * native mode and exit.
  619. */
  620. if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
  621. nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
  622. status = connector_status_connected;
  623. goto out;
  624. }
  625. /* Still nothing, some VBIOS images have a hardcoded EDID block
  626. * stored for the panel stored in them.
  627. */
  628. if (!drm->vbios.fp_no_ddc) {
  629. struct edid *edid =
  630. (struct edid *)nouveau_bios_embedded_edid(dev);
  631. if (edid) {
  632. nv_connector->edid =
  633. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  634. if (nv_connector->edid)
  635. status = connector_status_connected;
  636. }
  637. }
  638. out:
  639. #if defined(CONFIG_ACPI_BUTTON) || \
  640. (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
  641. if (status == connector_status_connected &&
  642. !nouveau_ignorelid && !acpi_lid_open())
  643. status = connector_status_unknown;
  644. #endif
  645. drm_mode_connector_update_edid_property(connector, nv_connector->edid);
  646. nouveau_connector_set_encoder(connector, nv_encoder);
  647. return status;
  648. }
  649. static void
  650. nouveau_connector_force(struct drm_connector *connector)
  651. {
  652. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  653. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  654. struct nouveau_encoder *nv_encoder;
  655. int type;
  656. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  657. if (connector->force == DRM_FORCE_ON_DIGITAL)
  658. type = DCB_OUTPUT_TMDS;
  659. else
  660. type = DCB_OUTPUT_ANALOG;
  661. } else
  662. type = DCB_OUTPUT_ANY;
  663. nv_encoder = find_encoder(connector, type);
  664. if (!nv_encoder) {
  665. NV_ERROR(drm, "can't find encoder to force %s on!\n",
  666. connector->name);
  667. connector->status = connector_status_disconnected;
  668. return;
  669. }
  670. nouveau_connector_set_encoder(connector, nv_encoder);
  671. }
  672. static int
  673. nouveau_connector_set_property(struct drm_connector *connector,
  674. struct drm_property *property, uint64_t value)
  675. {
  676. struct nouveau_conn_atom *asyc = nouveau_conn_atom(connector->state);
  677. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  678. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  679. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  680. int ret;
  681. if (drm_drv_uses_atomic_modeset(connector->dev))
  682. return drm_atomic_helper_connector_set_property(connector, property, value);
  683. ret = connector->funcs->atomic_set_property(&nv_connector->base,
  684. &asyc->state,
  685. property, value);
  686. if (ret) {
  687. if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
  688. return get_slave_funcs(encoder)->set_property(
  689. encoder, connector, property, value);
  690. return ret;
  691. }
  692. nv_connector->scaling_mode = asyc->scaler.mode;
  693. nv_connector->dithering_mode = asyc->dither.mode;
  694. if (connector->encoder && connector->encoder->crtc) {
  695. ret = drm_crtc_helper_set_mode(connector->encoder->crtc,
  696. &connector->encoder->crtc->mode,
  697. connector->encoder->crtc->x,
  698. connector->encoder->crtc->y,
  699. NULL);
  700. if (!ret)
  701. return -EINVAL;
  702. }
  703. return 0;
  704. }
  705. struct moderec {
  706. int hdisplay;
  707. int vdisplay;
  708. };
  709. static struct moderec scaler_modes[] = {
  710. { 1920, 1200 },
  711. { 1920, 1080 },
  712. { 1680, 1050 },
  713. { 1600, 1200 },
  714. { 1400, 1050 },
  715. { 1280, 1024 },
  716. { 1280, 960 },
  717. { 1152, 864 },
  718. { 1024, 768 },
  719. { 800, 600 },
  720. { 720, 400 },
  721. { 640, 480 },
  722. { 640, 400 },
  723. { 640, 350 },
  724. {}
  725. };
  726. static int
  727. nouveau_connector_scaler_modes_add(struct drm_connector *connector)
  728. {
  729. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  730. struct drm_display_mode *native = nv_connector->native_mode, *m;
  731. struct drm_device *dev = connector->dev;
  732. struct moderec *mode = &scaler_modes[0];
  733. int modes = 0;
  734. if (!native)
  735. return 0;
  736. while (mode->hdisplay) {
  737. if (mode->hdisplay <= native->hdisplay &&
  738. mode->vdisplay <= native->vdisplay &&
  739. (mode->hdisplay != native->hdisplay ||
  740. mode->vdisplay != native->vdisplay)) {
  741. m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
  742. drm_mode_vrefresh(native), false,
  743. false, false);
  744. if (!m)
  745. continue;
  746. drm_mode_probed_add(connector, m);
  747. modes++;
  748. }
  749. mode++;
  750. }
  751. return modes;
  752. }
  753. static void
  754. nouveau_connector_detect_depth(struct drm_connector *connector)
  755. {
  756. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  757. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  758. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  759. struct nvbios *bios = &drm->vbios;
  760. struct drm_display_mode *mode = nv_connector->native_mode;
  761. bool duallink;
  762. /* if the edid is feeling nice enough to provide this info, use it */
  763. if (nv_connector->edid && connector->display_info.bpc)
  764. return;
  765. /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
  766. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  767. connector->display_info.bpc = 6;
  768. return;
  769. }
  770. /* we're out of options unless we're LVDS, default to 8bpc */
  771. if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
  772. connector->display_info.bpc = 8;
  773. return;
  774. }
  775. connector->display_info.bpc = 6;
  776. /* LVDS: panel straps */
  777. if (bios->fp_no_ddc) {
  778. if (bios->fp.if_is_24bit)
  779. connector->display_info.bpc = 8;
  780. return;
  781. }
  782. /* LVDS: DDC panel, need to first determine the number of links to
  783. * know which if_is_24bit flag to check...
  784. */
  785. if (nv_connector->edid &&
  786. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
  787. duallink = ((u8 *)nv_connector->edid)[121] == 2;
  788. else
  789. duallink = mode->clock >= bios->fp.duallink_transition_clk;
  790. if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
  791. ( duallink && (bios->fp.strapless_is_24bit & 2)))
  792. connector->display_info.bpc = 8;
  793. }
  794. static int
  795. nouveau_connector_get_modes(struct drm_connector *connector)
  796. {
  797. struct drm_device *dev = connector->dev;
  798. struct nouveau_drm *drm = nouveau_drm(dev);
  799. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  800. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  801. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  802. int ret = 0;
  803. /* destroy the native mode, the attached monitor could have changed.
  804. */
  805. if (nv_connector->native_mode) {
  806. drm_mode_destroy(dev, nv_connector->native_mode);
  807. nv_connector->native_mode = NULL;
  808. }
  809. if (nv_connector->edid)
  810. ret = drm_add_edid_modes(connector, nv_connector->edid);
  811. else
  812. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
  813. (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
  814. drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
  815. struct drm_display_mode mode;
  816. nouveau_bios_fp_mode(dev, &mode);
  817. nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
  818. }
  819. /* Determine display colour depth for everything except LVDS now,
  820. * DP requires this before mode_valid() is called.
  821. */
  822. if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
  823. nouveau_connector_detect_depth(connector);
  824. /* Find the native mode if this is a digital panel, if we didn't
  825. * find any modes through DDC previously add the native mode to
  826. * the list of modes.
  827. */
  828. if (!nv_connector->native_mode)
  829. nv_connector->native_mode = nouveau_conn_native_mode(connector);
  830. if (ret == 0 && nv_connector->native_mode) {
  831. struct drm_display_mode *mode;
  832. mode = drm_mode_duplicate(dev, nv_connector->native_mode);
  833. drm_mode_probed_add(connector, mode);
  834. ret = 1;
  835. }
  836. /* Determine LVDS colour depth, must happen after determining
  837. * "native" mode as some VBIOS tables require us to use the
  838. * pixel clock as part of the lookup...
  839. */
  840. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
  841. nouveau_connector_detect_depth(connector);
  842. if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
  843. ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
  844. if (nv_connector->type == DCB_CONNECTOR_LVDS ||
  845. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
  846. nv_connector->type == DCB_CONNECTOR_eDP)
  847. ret += nouveau_connector_scaler_modes_add(connector);
  848. return ret;
  849. }
  850. static unsigned
  851. get_tmds_link_bandwidth(struct drm_connector *connector, bool hdmi)
  852. {
  853. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  854. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  855. struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
  856. if (hdmi) {
  857. if (nouveau_hdmimhz > 0)
  858. return nouveau_hdmimhz * 1000;
  859. /* Note: these limits are conservative, some Fermi's
  860. * can do 297 MHz. Unclear how this can be determined.
  861. */
  862. if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_KEPLER)
  863. return 297000;
  864. if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_FERMI)
  865. return 225000;
  866. }
  867. if (dcb->location != DCB_LOC_ON_CHIP ||
  868. drm->client.device.info.chipset >= 0x46)
  869. return 165000;
  870. else if (drm->client.device.info.chipset >= 0x40)
  871. return 155000;
  872. else if (drm->client.device.info.chipset >= 0x18)
  873. return 135000;
  874. else
  875. return 112000;
  876. }
  877. static int
  878. nouveau_connector_mode_valid(struct drm_connector *connector,
  879. struct drm_display_mode *mode)
  880. {
  881. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  882. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  883. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  884. unsigned min_clock = 25000, max_clock = min_clock;
  885. unsigned clock = mode->clock;
  886. bool hdmi;
  887. switch (nv_encoder->dcb->type) {
  888. case DCB_OUTPUT_LVDS:
  889. if (nv_connector->native_mode &&
  890. (mode->hdisplay > nv_connector->native_mode->hdisplay ||
  891. mode->vdisplay > nv_connector->native_mode->vdisplay))
  892. return MODE_PANEL;
  893. min_clock = 0;
  894. max_clock = 400000;
  895. break;
  896. case DCB_OUTPUT_TMDS:
  897. hdmi = drm_detect_hdmi_monitor(nv_connector->edid);
  898. max_clock = get_tmds_link_bandwidth(connector, hdmi);
  899. if (!hdmi && nouveau_duallink &&
  900. nv_encoder->dcb->duallink_possible)
  901. max_clock *= 2;
  902. break;
  903. case DCB_OUTPUT_ANALOG:
  904. max_clock = nv_encoder->dcb->crtconf.maxfreq;
  905. if (!max_clock)
  906. max_clock = 350000;
  907. break;
  908. case DCB_OUTPUT_TV:
  909. return get_slave_funcs(encoder)->mode_valid(encoder, mode);
  910. case DCB_OUTPUT_DP:
  911. max_clock = nv_encoder->dp.link_nr;
  912. max_clock *= nv_encoder->dp.link_bw;
  913. clock = clock * (connector->display_info.bpc * 3) / 10;
  914. break;
  915. default:
  916. BUG();
  917. return MODE_BAD;
  918. }
  919. if (clock < min_clock)
  920. return MODE_CLOCK_LOW;
  921. if (clock > max_clock)
  922. return MODE_CLOCK_HIGH;
  923. return MODE_OK;
  924. }
  925. static struct drm_encoder *
  926. nouveau_connector_best_encoder(struct drm_connector *connector)
  927. {
  928. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  929. if (nv_connector->detected_encoder)
  930. return to_drm_encoder(nv_connector->detected_encoder);
  931. return NULL;
  932. }
  933. static const struct drm_connector_helper_funcs
  934. nouveau_connector_helper_funcs = {
  935. .get_modes = nouveau_connector_get_modes,
  936. .mode_valid = nouveau_connector_mode_valid,
  937. .best_encoder = nouveau_connector_best_encoder,
  938. };
  939. static int
  940. nouveau_connector_dpms(struct drm_connector *connector, int mode)
  941. {
  942. if (drm_drv_uses_atomic_modeset(connector->dev))
  943. return drm_atomic_helper_connector_dpms(connector, mode);
  944. return drm_helper_connector_dpms(connector, mode);
  945. }
  946. static const struct drm_connector_funcs
  947. nouveau_connector_funcs = {
  948. .dpms = nouveau_connector_dpms,
  949. .reset = nouveau_conn_reset,
  950. .detect = nouveau_connector_detect,
  951. .force = nouveau_connector_force,
  952. .fill_modes = drm_helper_probe_single_connector_modes,
  953. .set_property = nouveau_connector_set_property,
  954. .destroy = nouveau_connector_destroy,
  955. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  956. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  957. .atomic_set_property = nouveau_conn_atomic_set_property,
  958. .atomic_get_property = nouveau_conn_atomic_get_property,
  959. };
  960. static const struct drm_connector_funcs
  961. nouveau_connector_funcs_lvds = {
  962. .dpms = nouveau_connector_dpms,
  963. .reset = nouveau_conn_reset,
  964. .detect = nouveau_connector_detect_lvds,
  965. .force = nouveau_connector_force,
  966. .fill_modes = drm_helper_probe_single_connector_modes,
  967. .set_property = nouveau_connector_set_property,
  968. .destroy = nouveau_connector_destroy,
  969. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  970. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  971. .atomic_set_property = nouveau_conn_atomic_set_property,
  972. .atomic_get_property = nouveau_conn_atomic_get_property,
  973. };
  974. static int
  975. nouveau_connector_hotplug(struct nvif_notify *notify)
  976. {
  977. struct nouveau_connector *nv_connector =
  978. container_of(notify, typeof(*nv_connector), hpd);
  979. struct drm_connector *connector = &nv_connector->base;
  980. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  981. const struct nvif_notify_conn_rep_v0 *rep = notify->data;
  982. const char *name = connector->name;
  983. struct nouveau_encoder *nv_encoder;
  984. if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
  985. NV_DEBUG(drm, "service %s\n", name);
  986. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP)))
  987. nv50_mstm_service(nv_encoder->dp.mstm);
  988. } else {
  989. bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG);
  990. NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
  991. if ((nv_encoder = find_encoder(connector, DCB_OUTPUT_DP))) {
  992. if (!plugged)
  993. nv50_mstm_remove(nv_encoder->dp.mstm);
  994. }
  995. drm_helper_hpd_irq_event(connector->dev);
  996. }
  997. return NVIF_NOTIFY_KEEP;
  998. }
  999. static ssize_t
  1000. nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg)
  1001. {
  1002. struct nouveau_connector *nv_connector =
  1003. container_of(obj, typeof(*nv_connector), aux);
  1004. struct nouveau_encoder *nv_encoder;
  1005. struct nvkm_i2c_aux *aux;
  1006. u8 size = msg->size;
  1007. int ret;
  1008. nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
  1009. if (!nv_encoder || !(aux = nv_encoder->aux))
  1010. return -ENODEV;
  1011. if (WARN_ON(msg->size > 16))
  1012. return -E2BIG;
  1013. if (msg->size == 0)
  1014. return msg->size;
  1015. ret = nvkm_i2c_aux_acquire(aux);
  1016. if (ret)
  1017. return ret;
  1018. ret = nvkm_i2c_aux_xfer(aux, false, msg->request, msg->address,
  1019. msg->buffer, &size);
  1020. nvkm_i2c_aux_release(aux);
  1021. if (ret >= 0) {
  1022. msg->reply = ret;
  1023. return size;
  1024. }
  1025. return ret;
  1026. }
  1027. static int
  1028. drm_conntype_from_dcb(enum dcb_connector_type dcb)
  1029. {
  1030. switch (dcb) {
  1031. case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA;
  1032. case DCB_CONNECTOR_TV_0 :
  1033. case DCB_CONNECTOR_TV_1 :
  1034. case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV;
  1035. case DCB_CONNECTOR_DMS59_0 :
  1036. case DCB_CONNECTOR_DMS59_1 :
  1037. case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII;
  1038. case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID;
  1039. case DCB_CONNECTOR_LVDS :
  1040. case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
  1041. case DCB_CONNECTOR_DMS59_DP0:
  1042. case DCB_CONNECTOR_DMS59_DP1:
  1043. case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort;
  1044. case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP;
  1045. case DCB_CONNECTOR_HDMI_0 :
  1046. case DCB_CONNECTOR_HDMI_1 :
  1047. case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA;
  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. /* defaults, will get overridden in detect() */
  1160. connector->interlace_allowed = false;
  1161. connector->doublescan_allowed = false;
  1162. drm_connector_init(dev, connector, funcs, type);
  1163. drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
  1164. connector->funcs->reset(connector);
  1165. nouveau_conn_attach_properties(connector);
  1166. /* Default scaling mode */
  1167. switch (nv_connector->type) {
  1168. case DCB_CONNECTOR_LVDS:
  1169. case DCB_CONNECTOR_LVDS_SPWG:
  1170. case DCB_CONNECTOR_eDP:
  1171. /* see note in nouveau_connector_set_property() */
  1172. if (disp->disp.oclass < NV50_DISP) {
  1173. nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
  1174. break;
  1175. }
  1176. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1177. break;
  1178. default:
  1179. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1180. break;
  1181. }
  1182. /* dithering properties */
  1183. switch (nv_connector->type) {
  1184. case DCB_CONNECTOR_TV_0:
  1185. case DCB_CONNECTOR_TV_1:
  1186. case DCB_CONNECTOR_TV_3:
  1187. case DCB_CONNECTOR_VGA:
  1188. break;
  1189. default:
  1190. nv_connector->dithering_mode = DITHERING_MODE_AUTO;
  1191. break;
  1192. }
  1193. ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true,
  1194. NV04_DISP_NTFY_CONN,
  1195. &(struct nvif_notify_conn_req_v0) {
  1196. .mask = NVIF_NOTIFY_CONN_V0_ANY,
  1197. .conn = index,
  1198. },
  1199. sizeof(struct nvif_notify_conn_req_v0),
  1200. sizeof(struct nvif_notify_conn_rep_v0),
  1201. &nv_connector->hpd);
  1202. if (ret)
  1203. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  1204. else
  1205. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1206. drm_connector_register(connector);
  1207. return connector;
  1208. }