nouveau_connector.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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 <drm/drmP.h>
  29. #include <drm/drm_edid.h>
  30. #include <drm/drm_crtc_helper.h>
  31. #include "nouveau_reg.h"
  32. #include "nouveau_drm.h"
  33. #include "dispnv04/hw.h"
  34. #include "nouveau_acpi.h"
  35. #include "nouveau_display.h"
  36. #include "nouveau_connector.h"
  37. #include "nouveau_encoder.h"
  38. #include "nouveau_crtc.h"
  39. #include <subdev/i2c.h>
  40. #include <subdev/gpio.h>
  41. #include <engine/disp.h>
  42. MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
  43. static int nouveau_tv_disable = 0;
  44. module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
  45. MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
  46. static int nouveau_ignorelid = 0;
  47. module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
  48. MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (default: enabled)");
  49. static int nouveau_duallink = 1;
  50. module_param_named(duallink, nouveau_duallink, int, 0400);
  51. struct nouveau_encoder *
  52. find_encoder(struct drm_connector *connector, int type)
  53. {
  54. struct drm_device *dev = connector->dev;
  55. struct nouveau_encoder *nv_encoder;
  56. struct drm_mode_object *obj;
  57. int i, id;
  58. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  59. id = connector->encoder_ids[i];
  60. if (!id)
  61. break;
  62. obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  63. if (!obj)
  64. continue;
  65. nv_encoder = nouveau_encoder(obj_to_encoder(obj));
  66. if (type == DCB_OUTPUT_ANY ||
  67. (nv_encoder->dcb && nv_encoder->dcb->type == type))
  68. return nv_encoder;
  69. }
  70. return NULL;
  71. }
  72. struct nouveau_connector *
  73. nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
  74. {
  75. struct drm_device *dev = to_drm_encoder(encoder)->dev;
  76. struct drm_connector *drm_connector;
  77. list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
  78. if (drm_connector->encoder == to_drm_encoder(encoder))
  79. return nouveau_connector(drm_connector);
  80. }
  81. return NULL;
  82. }
  83. static void
  84. nouveau_connector_destroy(struct drm_connector *connector)
  85. {
  86. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  87. nouveau_event_ref(NULL, &nv_connector->hpd);
  88. kfree(nv_connector->edid);
  89. drm_sysfs_connector_remove(connector);
  90. drm_connector_cleanup(connector);
  91. if (nv_connector->aux.transfer)
  92. drm_dp_aux_unregister(&nv_connector->aux);
  93. kfree(connector);
  94. }
  95. static struct nouveau_encoder *
  96. nouveau_connector_ddc_detect(struct drm_connector *connector)
  97. {
  98. struct drm_device *dev = connector->dev;
  99. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  100. struct nouveau_drm *drm = nouveau_drm(dev);
  101. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  102. struct nouveau_encoder *nv_encoder;
  103. struct drm_mode_object *obj;
  104. int i, panel = -ENODEV;
  105. /* eDP panels need powering on by us (if the VBIOS doesn't default it
  106. * to on) before doing any AUX channel transactions. LVDS panel power
  107. * is handled by the SOR itself, and not required for LVDS DDC.
  108. */
  109. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  110. panel = gpio->get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
  111. if (panel == 0) {
  112. gpio->set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
  113. msleep(300);
  114. }
  115. }
  116. for (i = 0; nv_encoder = NULL, i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  117. int id = connector->encoder_ids[i];
  118. if (id == 0)
  119. break;
  120. obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  121. if (!obj)
  122. continue;
  123. nv_encoder = nouveau_encoder(obj_to_encoder(obj));
  124. if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
  125. int ret = nouveau_dp_detect(nv_encoder);
  126. if (ret == 0)
  127. break;
  128. } else
  129. if (nv_encoder->i2c) {
  130. if (nv_probe_i2c(nv_encoder->i2c, 0x50))
  131. break;
  132. }
  133. }
  134. /* eDP panel not detected, restore panel power GPIO to previous
  135. * state to avoid confusing the SOR for other output types.
  136. */
  137. if (!nv_encoder && panel == 0)
  138. gpio->set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel);
  139. return nv_encoder;
  140. }
  141. static struct nouveau_encoder *
  142. nouveau_connector_of_detect(struct drm_connector *connector)
  143. {
  144. #ifdef __powerpc__
  145. struct drm_device *dev = connector->dev;
  146. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  147. struct nouveau_encoder *nv_encoder;
  148. struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
  149. if (!dn ||
  150. !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) ||
  151. (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG))))
  152. return NULL;
  153. for_each_child_of_node(dn, cn) {
  154. const char *name = of_get_property(cn, "name", NULL);
  155. const void *edid = of_get_property(cn, "EDID", NULL);
  156. int idx = name ? name[strlen(name) - 1] - 'A' : 0;
  157. if (nv_encoder->dcb->i2c_index == idx && edid) {
  158. nv_connector->edid =
  159. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  160. of_node_put(cn);
  161. return nv_encoder;
  162. }
  163. }
  164. #endif
  165. return NULL;
  166. }
  167. static void
  168. nouveau_connector_set_encoder(struct drm_connector *connector,
  169. struct nouveau_encoder *nv_encoder)
  170. {
  171. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  172. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  173. struct drm_device *dev = connector->dev;
  174. if (nv_connector->detected_encoder == nv_encoder)
  175. return;
  176. nv_connector->detected_encoder = nv_encoder;
  177. if (nv_device(drm->device)->card_type >= NV_50) {
  178. connector->interlace_allowed = true;
  179. connector->doublescan_allowed = true;
  180. } else
  181. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS ||
  182. nv_encoder->dcb->type == DCB_OUTPUT_TMDS) {
  183. connector->doublescan_allowed = false;
  184. connector->interlace_allowed = false;
  185. } else {
  186. connector->doublescan_allowed = true;
  187. if (nv_device(drm->device)->card_type == NV_20 ||
  188. ((nv_device(drm->device)->card_type == NV_10 ||
  189. nv_device(drm->device)->card_type == NV_11) &&
  190. (dev->pdev->device & 0x0ff0) != 0x0100 &&
  191. (dev->pdev->device & 0x0ff0) != 0x0150))
  192. /* HW is broken */
  193. connector->interlace_allowed = false;
  194. else
  195. connector->interlace_allowed = true;
  196. }
  197. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  198. drm_object_property_set_value(&connector->base,
  199. dev->mode_config.dvi_i_subconnector_property,
  200. nv_encoder->dcb->type == DCB_OUTPUT_TMDS ?
  201. DRM_MODE_SUBCONNECTOR_DVID :
  202. DRM_MODE_SUBCONNECTOR_DVIA);
  203. }
  204. }
  205. static enum drm_connector_status
  206. nouveau_connector_detect(struct drm_connector *connector, bool force)
  207. {
  208. struct drm_device *dev = connector->dev;
  209. struct nouveau_drm *drm = nouveau_drm(dev);
  210. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  211. struct nouveau_encoder *nv_encoder = NULL;
  212. struct nouveau_encoder *nv_partner;
  213. struct nouveau_i2c_port *i2c;
  214. int type;
  215. int ret;
  216. enum drm_connector_status conn_status = connector_status_disconnected;
  217. /* Cleanup the previous EDID block. */
  218. if (nv_connector->edid) {
  219. drm_mode_connector_update_edid_property(connector, NULL);
  220. kfree(nv_connector->edid);
  221. nv_connector->edid = NULL;
  222. }
  223. ret = pm_runtime_get_sync(connector->dev->dev);
  224. if (ret < 0 && ret != -EACCES)
  225. return conn_status;
  226. nv_encoder = nouveau_connector_ddc_detect(connector);
  227. if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
  228. nv_connector->edid = drm_get_edid(connector, &i2c->adapter);
  229. drm_mode_connector_update_edid_property(connector,
  230. nv_connector->edid);
  231. if (!nv_connector->edid) {
  232. NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
  233. connector->name);
  234. goto detect_analog;
  235. }
  236. /* Override encoder type for DVI-I based on whether EDID
  237. * says the display is digital or analog, both use the
  238. * same i2c channel so the value returned from ddc_detect
  239. * isn't necessarily correct.
  240. */
  241. nv_partner = NULL;
  242. if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
  243. nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
  244. if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
  245. nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
  246. if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
  247. nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
  248. (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
  249. nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
  250. if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
  251. type = DCB_OUTPUT_TMDS;
  252. else
  253. type = DCB_OUTPUT_ANALOG;
  254. nv_encoder = find_encoder(connector, type);
  255. }
  256. nouveau_connector_set_encoder(connector, nv_encoder);
  257. conn_status = connector_status_connected;
  258. goto out;
  259. }
  260. nv_encoder = nouveau_connector_of_detect(connector);
  261. if (nv_encoder) {
  262. nouveau_connector_set_encoder(connector, nv_encoder);
  263. conn_status = connector_status_connected;
  264. goto out;
  265. }
  266. detect_analog:
  267. nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
  268. if (!nv_encoder && !nouveau_tv_disable)
  269. nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
  270. if (nv_encoder && force) {
  271. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  272. struct drm_encoder_helper_funcs *helper =
  273. encoder->helper_private;
  274. if (helper->detect(encoder, connector) ==
  275. connector_status_connected) {
  276. nouveau_connector_set_encoder(connector, nv_encoder);
  277. conn_status = connector_status_connected;
  278. goto out;
  279. }
  280. }
  281. out:
  282. pm_runtime_mark_last_busy(connector->dev->dev);
  283. pm_runtime_put_autosuspend(connector->dev->dev);
  284. return conn_status;
  285. }
  286. static enum drm_connector_status
  287. nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
  288. {
  289. struct drm_device *dev = connector->dev;
  290. struct nouveau_drm *drm = nouveau_drm(dev);
  291. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  292. struct nouveau_encoder *nv_encoder = NULL;
  293. enum drm_connector_status status = connector_status_disconnected;
  294. /* Cleanup the previous EDID block. */
  295. if (nv_connector->edid) {
  296. drm_mode_connector_update_edid_property(connector, NULL);
  297. kfree(nv_connector->edid);
  298. nv_connector->edid = NULL;
  299. }
  300. nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
  301. if (!nv_encoder)
  302. return connector_status_disconnected;
  303. /* Try retrieving EDID via DDC */
  304. if (!drm->vbios.fp_no_ddc) {
  305. status = nouveau_connector_detect(connector, force);
  306. if (status == connector_status_connected)
  307. goto out;
  308. }
  309. /* On some laptops (Sony, i'm looking at you) there appears to
  310. * be no direct way of accessing the panel's EDID. The only
  311. * option available to us appears to be to ask ACPI for help..
  312. *
  313. * It's important this check's before trying straps, one of the
  314. * said manufacturer's laptops are configured in such a way
  315. * the nouveau decides an entry in the VBIOS FP mode table is
  316. * valid - it's not (rh#613284)
  317. */
  318. if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
  319. if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
  320. status = connector_status_connected;
  321. goto out;
  322. }
  323. }
  324. /* If no EDID found above, and the VBIOS indicates a hardcoded
  325. * modeline is avalilable for the panel, set it as the panel's
  326. * native mode and exit.
  327. */
  328. if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
  329. nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
  330. status = connector_status_connected;
  331. goto out;
  332. }
  333. /* Still nothing, some VBIOS images have a hardcoded EDID block
  334. * stored for the panel stored in them.
  335. */
  336. if (!drm->vbios.fp_no_ddc) {
  337. struct edid *edid =
  338. (struct edid *)nouveau_bios_embedded_edid(dev);
  339. if (edid) {
  340. nv_connector->edid =
  341. kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
  342. if (nv_connector->edid)
  343. status = connector_status_connected;
  344. }
  345. }
  346. out:
  347. #if defined(CONFIG_ACPI_BUTTON) || \
  348. (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
  349. if (status == connector_status_connected &&
  350. !nouveau_ignorelid && !acpi_lid_open())
  351. status = connector_status_unknown;
  352. #endif
  353. drm_mode_connector_update_edid_property(connector, nv_connector->edid);
  354. nouveau_connector_set_encoder(connector, nv_encoder);
  355. return status;
  356. }
  357. static void
  358. nouveau_connector_force(struct drm_connector *connector)
  359. {
  360. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  361. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  362. struct nouveau_encoder *nv_encoder;
  363. int type;
  364. if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
  365. if (connector->force == DRM_FORCE_ON_DIGITAL)
  366. type = DCB_OUTPUT_TMDS;
  367. else
  368. type = DCB_OUTPUT_ANALOG;
  369. } else
  370. type = DCB_OUTPUT_ANY;
  371. nv_encoder = find_encoder(connector, type);
  372. if (!nv_encoder) {
  373. NV_ERROR(drm, "can't find encoder to force %s on!\n",
  374. connector->name);
  375. connector->status = connector_status_disconnected;
  376. return;
  377. }
  378. nouveau_connector_set_encoder(connector, nv_encoder);
  379. }
  380. static int
  381. nouveau_connector_set_property(struct drm_connector *connector,
  382. struct drm_property *property, uint64_t value)
  383. {
  384. struct nouveau_display *disp = nouveau_display(connector->dev);
  385. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  386. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  387. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  388. struct drm_device *dev = connector->dev;
  389. struct nouveau_crtc *nv_crtc;
  390. int ret;
  391. nv_crtc = NULL;
  392. if (connector->encoder && connector->encoder->crtc)
  393. nv_crtc = nouveau_crtc(connector->encoder->crtc);
  394. /* Scaling mode */
  395. if (property == dev->mode_config.scaling_mode_property) {
  396. bool modeset = false;
  397. switch (value) {
  398. case DRM_MODE_SCALE_NONE:
  399. case DRM_MODE_SCALE_FULLSCREEN:
  400. case DRM_MODE_SCALE_CENTER:
  401. case DRM_MODE_SCALE_ASPECT:
  402. break;
  403. default:
  404. return -EINVAL;
  405. }
  406. /* LVDS always needs gpu scaling */
  407. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
  408. value == DRM_MODE_SCALE_NONE)
  409. return -EINVAL;
  410. /* Changing between GPU and panel scaling requires a full
  411. * modeset
  412. */
  413. if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
  414. (value == DRM_MODE_SCALE_NONE))
  415. modeset = true;
  416. nv_connector->scaling_mode = value;
  417. if (!nv_crtc)
  418. return 0;
  419. if (modeset || !nv_crtc->set_scale) {
  420. ret = drm_crtc_helper_set_mode(&nv_crtc->base,
  421. &nv_crtc->base.mode,
  422. nv_crtc->base.x,
  423. nv_crtc->base.y, NULL);
  424. if (!ret)
  425. return -EINVAL;
  426. } else {
  427. ret = nv_crtc->set_scale(nv_crtc, true);
  428. if (ret)
  429. return ret;
  430. }
  431. return 0;
  432. }
  433. /* Underscan */
  434. if (property == disp->underscan_property) {
  435. if (nv_connector->underscan != value) {
  436. nv_connector->underscan = value;
  437. if (!nv_crtc || !nv_crtc->set_scale)
  438. return 0;
  439. return nv_crtc->set_scale(nv_crtc, true);
  440. }
  441. return 0;
  442. }
  443. if (property == disp->underscan_hborder_property) {
  444. if (nv_connector->underscan_hborder != value) {
  445. nv_connector->underscan_hborder = value;
  446. if (!nv_crtc || !nv_crtc->set_scale)
  447. return 0;
  448. return nv_crtc->set_scale(nv_crtc, true);
  449. }
  450. return 0;
  451. }
  452. if (property == disp->underscan_vborder_property) {
  453. if (nv_connector->underscan_vborder != value) {
  454. nv_connector->underscan_vborder = value;
  455. if (!nv_crtc || !nv_crtc->set_scale)
  456. return 0;
  457. return nv_crtc->set_scale(nv_crtc, true);
  458. }
  459. return 0;
  460. }
  461. /* Dithering */
  462. if (property == disp->dithering_mode) {
  463. nv_connector->dithering_mode = value;
  464. if (!nv_crtc || !nv_crtc->set_dither)
  465. return 0;
  466. return nv_crtc->set_dither(nv_crtc, true);
  467. }
  468. if (property == disp->dithering_depth) {
  469. nv_connector->dithering_depth = value;
  470. if (!nv_crtc || !nv_crtc->set_dither)
  471. return 0;
  472. return nv_crtc->set_dither(nv_crtc, true);
  473. }
  474. if (nv_crtc && nv_crtc->set_color_vibrance) {
  475. /* Hue */
  476. if (property == disp->vibrant_hue_property) {
  477. nv_crtc->vibrant_hue = value - 90;
  478. return nv_crtc->set_color_vibrance(nv_crtc, true);
  479. }
  480. /* Saturation */
  481. if (property == disp->color_vibrance_property) {
  482. nv_crtc->color_vibrance = value - 100;
  483. return nv_crtc->set_color_vibrance(nv_crtc, true);
  484. }
  485. }
  486. if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
  487. return get_slave_funcs(encoder)->set_property(
  488. encoder, connector, property, value);
  489. return -EINVAL;
  490. }
  491. static struct drm_display_mode *
  492. nouveau_connector_native_mode(struct drm_connector *connector)
  493. {
  494. struct drm_connector_helper_funcs *helper = connector->helper_private;
  495. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  496. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  497. struct drm_device *dev = connector->dev;
  498. struct drm_display_mode *mode, *largest = NULL;
  499. int high_w = 0, high_h = 0, high_v = 0;
  500. list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
  501. mode->vrefresh = drm_mode_vrefresh(mode);
  502. if (helper->mode_valid(connector, mode) != MODE_OK ||
  503. (mode->flags & DRM_MODE_FLAG_INTERLACE))
  504. continue;
  505. /* Use preferred mode if there is one.. */
  506. if (mode->type & DRM_MODE_TYPE_PREFERRED) {
  507. NV_DEBUG(drm, "native mode from preferred\n");
  508. return drm_mode_duplicate(dev, mode);
  509. }
  510. /* Otherwise, take the resolution with the largest width, then
  511. * height, then vertical refresh
  512. */
  513. if (mode->hdisplay < high_w)
  514. continue;
  515. if (mode->hdisplay == high_w && mode->vdisplay < high_h)
  516. continue;
  517. if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
  518. mode->vrefresh < high_v)
  519. continue;
  520. high_w = mode->hdisplay;
  521. high_h = mode->vdisplay;
  522. high_v = mode->vrefresh;
  523. largest = mode;
  524. }
  525. NV_DEBUG(drm, "native mode from largest: %dx%d@%d\n",
  526. high_w, high_h, high_v);
  527. return largest ? drm_mode_duplicate(dev, largest) : NULL;
  528. }
  529. struct moderec {
  530. int hdisplay;
  531. int vdisplay;
  532. };
  533. static struct moderec scaler_modes[] = {
  534. { 1920, 1200 },
  535. { 1920, 1080 },
  536. { 1680, 1050 },
  537. { 1600, 1200 },
  538. { 1400, 1050 },
  539. { 1280, 1024 },
  540. { 1280, 960 },
  541. { 1152, 864 },
  542. { 1024, 768 },
  543. { 800, 600 },
  544. { 720, 400 },
  545. { 640, 480 },
  546. { 640, 400 },
  547. { 640, 350 },
  548. {}
  549. };
  550. static int
  551. nouveau_connector_scaler_modes_add(struct drm_connector *connector)
  552. {
  553. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  554. struct drm_display_mode *native = nv_connector->native_mode, *m;
  555. struct drm_device *dev = connector->dev;
  556. struct moderec *mode = &scaler_modes[0];
  557. int modes = 0;
  558. if (!native)
  559. return 0;
  560. while (mode->hdisplay) {
  561. if (mode->hdisplay <= native->hdisplay &&
  562. mode->vdisplay <= native->vdisplay) {
  563. m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
  564. drm_mode_vrefresh(native), false,
  565. false, false);
  566. if (!m)
  567. continue;
  568. m->type |= DRM_MODE_TYPE_DRIVER;
  569. drm_mode_probed_add(connector, m);
  570. modes++;
  571. }
  572. mode++;
  573. }
  574. return modes;
  575. }
  576. static void
  577. nouveau_connector_detect_depth(struct drm_connector *connector)
  578. {
  579. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  580. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  581. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  582. struct nvbios *bios = &drm->vbios;
  583. struct drm_display_mode *mode = nv_connector->native_mode;
  584. bool duallink;
  585. /* if the edid is feeling nice enough to provide this info, use it */
  586. if (nv_connector->edid && connector->display_info.bpc)
  587. return;
  588. /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
  589. if (nv_connector->type == DCB_CONNECTOR_eDP) {
  590. connector->display_info.bpc = 6;
  591. return;
  592. }
  593. /* we're out of options unless we're LVDS, default to 8bpc */
  594. if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
  595. connector->display_info.bpc = 8;
  596. return;
  597. }
  598. connector->display_info.bpc = 6;
  599. /* LVDS: panel straps */
  600. if (bios->fp_no_ddc) {
  601. if (bios->fp.if_is_24bit)
  602. connector->display_info.bpc = 8;
  603. return;
  604. }
  605. /* LVDS: DDC panel, need to first determine the number of links to
  606. * know which if_is_24bit flag to check...
  607. */
  608. if (nv_connector->edid &&
  609. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
  610. duallink = ((u8 *)nv_connector->edid)[121] == 2;
  611. else
  612. duallink = mode->clock >= bios->fp.duallink_transition_clk;
  613. if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
  614. ( duallink && (bios->fp.strapless_is_24bit & 2)))
  615. connector->display_info.bpc = 8;
  616. }
  617. static int
  618. nouveau_connector_get_modes(struct drm_connector *connector)
  619. {
  620. struct drm_device *dev = connector->dev;
  621. struct nouveau_drm *drm = nouveau_drm(dev);
  622. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  623. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  624. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  625. int ret = 0;
  626. /* destroy the native mode, the attached monitor could have changed.
  627. */
  628. if (nv_connector->native_mode) {
  629. drm_mode_destroy(dev, nv_connector->native_mode);
  630. nv_connector->native_mode = NULL;
  631. }
  632. if (nv_connector->edid)
  633. ret = drm_add_edid_modes(connector, nv_connector->edid);
  634. else
  635. if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
  636. (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
  637. drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
  638. struct drm_display_mode mode;
  639. nouveau_bios_fp_mode(dev, &mode);
  640. nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
  641. }
  642. /* Determine display colour depth for everything except LVDS now,
  643. * DP requires this before mode_valid() is called.
  644. */
  645. if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
  646. nouveau_connector_detect_depth(connector);
  647. /* Find the native mode if this is a digital panel, if we didn't
  648. * find any modes through DDC previously add the native mode to
  649. * the list of modes.
  650. */
  651. if (!nv_connector->native_mode)
  652. nv_connector->native_mode =
  653. nouveau_connector_native_mode(connector);
  654. if (ret == 0 && nv_connector->native_mode) {
  655. struct drm_display_mode *mode;
  656. mode = drm_mode_duplicate(dev, nv_connector->native_mode);
  657. drm_mode_probed_add(connector, mode);
  658. ret = 1;
  659. }
  660. /* Determine LVDS colour depth, must happen after determining
  661. * "native" mode as some VBIOS tables require us to use the
  662. * pixel clock as part of the lookup...
  663. */
  664. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
  665. nouveau_connector_detect_depth(connector);
  666. if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
  667. ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
  668. if (nv_connector->type == DCB_CONNECTOR_LVDS ||
  669. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
  670. nv_connector->type == DCB_CONNECTOR_eDP)
  671. ret += nouveau_connector_scaler_modes_add(connector);
  672. return ret;
  673. }
  674. static unsigned
  675. get_tmds_link_bandwidth(struct drm_connector *connector)
  676. {
  677. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  678. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  679. struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
  680. if (dcb->location != DCB_LOC_ON_CHIP ||
  681. nv_device(drm->device)->chipset >= 0x46)
  682. return 165000;
  683. else if (nv_device(drm->device)->chipset >= 0x40)
  684. return 155000;
  685. else if (nv_device(drm->device)->chipset >= 0x18)
  686. return 135000;
  687. else
  688. return 112000;
  689. }
  690. static int
  691. nouveau_connector_mode_valid(struct drm_connector *connector,
  692. struct drm_display_mode *mode)
  693. {
  694. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  695. struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
  696. struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
  697. unsigned min_clock = 25000, max_clock = min_clock;
  698. unsigned clock = mode->clock;
  699. switch (nv_encoder->dcb->type) {
  700. case DCB_OUTPUT_LVDS:
  701. if (nv_connector->native_mode &&
  702. (mode->hdisplay > nv_connector->native_mode->hdisplay ||
  703. mode->vdisplay > nv_connector->native_mode->vdisplay))
  704. return MODE_PANEL;
  705. min_clock = 0;
  706. max_clock = 400000;
  707. break;
  708. case DCB_OUTPUT_TMDS:
  709. max_clock = get_tmds_link_bandwidth(connector);
  710. if (nouveau_duallink && nv_encoder->dcb->duallink_possible)
  711. max_clock *= 2;
  712. break;
  713. case DCB_OUTPUT_ANALOG:
  714. max_clock = nv_encoder->dcb->crtconf.maxfreq;
  715. if (!max_clock)
  716. max_clock = 350000;
  717. break;
  718. case DCB_OUTPUT_TV:
  719. return get_slave_funcs(encoder)->mode_valid(encoder, mode);
  720. case DCB_OUTPUT_DP:
  721. max_clock = nv_encoder->dp.link_nr;
  722. max_clock *= nv_encoder->dp.link_bw;
  723. clock = clock * (connector->display_info.bpc * 3) / 10;
  724. break;
  725. default:
  726. BUG_ON(1);
  727. return MODE_BAD;
  728. }
  729. if (clock < min_clock)
  730. return MODE_CLOCK_LOW;
  731. if (clock > max_clock)
  732. return MODE_CLOCK_HIGH;
  733. return MODE_OK;
  734. }
  735. static struct drm_encoder *
  736. nouveau_connector_best_encoder(struct drm_connector *connector)
  737. {
  738. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  739. if (nv_connector->detected_encoder)
  740. return to_drm_encoder(nv_connector->detected_encoder);
  741. return NULL;
  742. }
  743. static const struct drm_connector_helper_funcs
  744. nouveau_connector_helper_funcs = {
  745. .get_modes = nouveau_connector_get_modes,
  746. .mode_valid = nouveau_connector_mode_valid,
  747. .best_encoder = nouveau_connector_best_encoder,
  748. };
  749. static const struct drm_connector_funcs
  750. nouveau_connector_funcs = {
  751. .dpms = drm_helper_connector_dpms,
  752. .save = NULL,
  753. .restore = NULL,
  754. .detect = nouveau_connector_detect,
  755. .destroy = nouveau_connector_destroy,
  756. .fill_modes = drm_helper_probe_single_connector_modes,
  757. .set_property = nouveau_connector_set_property,
  758. .force = nouveau_connector_force
  759. };
  760. static const struct drm_connector_funcs
  761. nouveau_connector_funcs_lvds = {
  762. .dpms = drm_helper_connector_dpms,
  763. .save = NULL,
  764. .restore = NULL,
  765. .detect = nouveau_connector_detect_lvds,
  766. .destroy = nouveau_connector_destroy,
  767. .fill_modes = drm_helper_probe_single_connector_modes,
  768. .set_property = nouveau_connector_set_property,
  769. .force = nouveau_connector_force
  770. };
  771. static void
  772. nouveau_connector_dp_dpms(struct drm_connector *connector, int mode)
  773. {
  774. struct nouveau_encoder *nv_encoder = NULL;
  775. if (connector->encoder)
  776. nv_encoder = nouveau_encoder(connector->encoder);
  777. if (nv_encoder && nv_encoder->dcb &&
  778. nv_encoder->dcb->type == DCB_OUTPUT_DP) {
  779. if (mode == DRM_MODE_DPMS_ON) {
  780. u8 data = DP_SET_POWER_D0;
  781. nv_wraux(nv_encoder->i2c, DP_SET_POWER, &data, 1);
  782. usleep_range(1000, 2000);
  783. } else {
  784. u8 data = DP_SET_POWER_D3;
  785. nv_wraux(nv_encoder->i2c, DP_SET_POWER, &data, 1);
  786. }
  787. }
  788. drm_helper_connector_dpms(connector, mode);
  789. }
  790. static const struct drm_connector_funcs
  791. nouveau_connector_funcs_dp = {
  792. .dpms = nouveau_connector_dp_dpms,
  793. .save = NULL,
  794. .restore = NULL,
  795. .detect = nouveau_connector_detect,
  796. .destroy = nouveau_connector_destroy,
  797. .fill_modes = drm_helper_probe_single_connector_modes,
  798. .set_property = nouveau_connector_set_property,
  799. .force = nouveau_connector_force
  800. };
  801. static void
  802. nouveau_connector_hotplug_work(struct work_struct *work)
  803. {
  804. struct nouveau_connector *nv_connector =
  805. container_of(work, typeof(*nv_connector), work);
  806. struct drm_connector *connector = &nv_connector->base;
  807. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  808. const char *name = connector->name;
  809. if (nv_connector->status & NVKM_HPD_IRQ) {
  810. } else {
  811. bool plugged = (nv_connector->status != NVKM_HPD_UNPLUG);
  812. NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
  813. if (plugged)
  814. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  815. else
  816. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  817. drm_helper_hpd_irq_event(connector->dev);
  818. }
  819. nouveau_event_get(nv_connector->hpd);
  820. }
  821. static int
  822. nouveau_connector_hotplug(void *data, u32 type, int index)
  823. {
  824. struct nouveau_connector *nv_connector = data;
  825. nv_connector->status = type;
  826. schedule_work(&nv_connector->work);
  827. return NVKM_EVENT_DROP;
  828. }
  829. static ssize_t
  830. nouveau_connector_aux_xfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  831. {
  832. struct nouveau_connector *nv_connector =
  833. container_of(aux, typeof(*nv_connector), aux);
  834. struct nouveau_encoder *nv_encoder;
  835. struct nouveau_i2c_port *port;
  836. int ret;
  837. nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
  838. if (!nv_encoder || !(port = nv_encoder->i2c))
  839. return -ENODEV;
  840. if (WARN_ON(msg->size > 16))
  841. return -E2BIG;
  842. if (msg->size == 0)
  843. return msg->size;
  844. ret = nouveau_i2c(port)->acquire(port, 0);
  845. if (ret)
  846. return ret;
  847. ret = port->func->aux(port, false, msg->request, msg->address,
  848. msg->buffer, msg->size);
  849. nouveau_i2c(port)->release(port);
  850. if (ret >= 0) {
  851. msg->reply = ret;
  852. return msg->size;
  853. }
  854. return ret;
  855. }
  856. static int
  857. drm_conntype_from_dcb(enum dcb_connector_type dcb)
  858. {
  859. switch (dcb) {
  860. case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA;
  861. case DCB_CONNECTOR_TV_0 :
  862. case DCB_CONNECTOR_TV_1 :
  863. case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV;
  864. case DCB_CONNECTOR_DMS59_0 :
  865. case DCB_CONNECTOR_DMS59_1 :
  866. case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII;
  867. case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID;
  868. case DCB_CONNECTOR_LVDS :
  869. case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
  870. case DCB_CONNECTOR_DMS59_DP0:
  871. case DCB_CONNECTOR_DMS59_DP1:
  872. case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort;
  873. case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP;
  874. case DCB_CONNECTOR_HDMI_0 :
  875. case DCB_CONNECTOR_HDMI_1 :
  876. case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA;
  877. default:
  878. break;
  879. }
  880. return DRM_MODE_CONNECTOR_Unknown;
  881. }
  882. struct drm_connector *
  883. nouveau_connector_create(struct drm_device *dev, int index)
  884. {
  885. const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
  886. struct nouveau_drm *drm = nouveau_drm(dev);
  887. struct nouveau_display *disp = nouveau_display(dev);
  888. struct nouveau_connector *nv_connector = NULL;
  889. struct nouveau_disp *pdisp = nouveau_disp(drm->device);
  890. struct drm_connector *connector;
  891. int type, ret = 0;
  892. bool dummy;
  893. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  894. nv_connector = nouveau_connector(connector);
  895. if (nv_connector->index == index)
  896. return connector;
  897. }
  898. nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
  899. if (!nv_connector)
  900. return ERR_PTR(-ENOMEM);
  901. connector = &nv_connector->base;
  902. nv_connector->index = index;
  903. /* attempt to parse vbios connector type and hotplug gpio */
  904. nv_connector->dcb = olddcb_conn(dev, index);
  905. if (nv_connector->dcb) {
  906. u32 entry = ROM16(nv_connector->dcb[0]);
  907. if (olddcb_conntab(dev)[3] >= 4)
  908. entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
  909. nv_connector->type = nv_connector->dcb[0];
  910. if (drm_conntype_from_dcb(nv_connector->type) ==
  911. DRM_MODE_CONNECTOR_Unknown) {
  912. NV_WARN(drm, "unknown connector type %02x\n",
  913. nv_connector->type);
  914. nv_connector->type = DCB_CONNECTOR_NONE;
  915. }
  916. /* Gigabyte NX85T */
  917. if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
  918. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  919. nv_connector->type = DCB_CONNECTOR_DVI_I;
  920. }
  921. /* Gigabyte GV-NX86T512H */
  922. if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
  923. if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
  924. nv_connector->type = DCB_CONNECTOR_DVI_I;
  925. }
  926. } else {
  927. nv_connector->type = DCB_CONNECTOR_NONE;
  928. }
  929. /* no vbios data, or an unknown dcb connector type - attempt to
  930. * figure out something suitable ourselves
  931. */
  932. if (nv_connector->type == DCB_CONNECTOR_NONE) {
  933. struct nouveau_drm *drm = nouveau_drm(dev);
  934. struct dcb_table *dcbt = &drm->vbios.dcb;
  935. u32 encoders = 0;
  936. int i;
  937. for (i = 0; i < dcbt->entries; i++) {
  938. if (dcbt->entry[i].connector == nv_connector->index)
  939. encoders |= (1 << dcbt->entry[i].type);
  940. }
  941. if (encoders & (1 << DCB_OUTPUT_DP)) {
  942. if (encoders & (1 << DCB_OUTPUT_TMDS))
  943. nv_connector->type = DCB_CONNECTOR_DP;
  944. else
  945. nv_connector->type = DCB_CONNECTOR_eDP;
  946. } else
  947. if (encoders & (1 << DCB_OUTPUT_TMDS)) {
  948. if (encoders & (1 << DCB_OUTPUT_ANALOG))
  949. nv_connector->type = DCB_CONNECTOR_DVI_I;
  950. else
  951. nv_connector->type = DCB_CONNECTOR_DVI_D;
  952. } else
  953. if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
  954. nv_connector->type = DCB_CONNECTOR_VGA;
  955. } else
  956. if (encoders & (1 << DCB_OUTPUT_LVDS)) {
  957. nv_connector->type = DCB_CONNECTOR_LVDS;
  958. } else
  959. if (encoders & (1 << DCB_OUTPUT_TV)) {
  960. nv_connector->type = DCB_CONNECTOR_TV_0;
  961. }
  962. }
  963. switch ((type = drm_conntype_from_dcb(nv_connector->type))) {
  964. case DRM_MODE_CONNECTOR_LVDS:
  965. ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
  966. if (ret) {
  967. NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
  968. kfree(nv_connector);
  969. return ERR_PTR(ret);
  970. }
  971. funcs = &nouveau_connector_funcs_lvds;
  972. break;
  973. case DRM_MODE_CONNECTOR_DisplayPort:
  974. case DRM_MODE_CONNECTOR_eDP:
  975. nv_connector->aux.dev = dev->dev;
  976. nv_connector->aux.transfer = nouveau_connector_aux_xfer;
  977. ret = drm_dp_aux_register(&nv_connector->aux);
  978. if (ret) {
  979. NV_ERROR(drm, "failed to register aux channel\n");
  980. kfree(nv_connector);
  981. return ERR_PTR(ret);
  982. }
  983. funcs = &nouveau_connector_funcs_dp;
  984. break;
  985. default:
  986. funcs = &nouveau_connector_funcs;
  987. break;
  988. }
  989. /* defaults, will get overridden in detect() */
  990. connector->interlace_allowed = false;
  991. connector->doublescan_allowed = false;
  992. drm_connector_init(dev, connector, funcs, type);
  993. drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
  994. /* Init DVI-I specific properties */
  995. if (nv_connector->type == DCB_CONNECTOR_DVI_I)
  996. drm_object_attach_property(&connector->base, dev->mode_config.dvi_i_subconnector_property, 0);
  997. /* Add overscan compensation options to digital outputs */
  998. if (disp->underscan_property &&
  999. (type == DRM_MODE_CONNECTOR_DVID ||
  1000. type == DRM_MODE_CONNECTOR_DVII ||
  1001. type == DRM_MODE_CONNECTOR_HDMIA ||
  1002. type == DRM_MODE_CONNECTOR_DisplayPort)) {
  1003. drm_object_attach_property(&connector->base,
  1004. disp->underscan_property,
  1005. UNDERSCAN_OFF);
  1006. drm_object_attach_property(&connector->base,
  1007. disp->underscan_hborder_property,
  1008. 0);
  1009. drm_object_attach_property(&connector->base,
  1010. disp->underscan_vborder_property,
  1011. 0);
  1012. }
  1013. /* Add hue and saturation options */
  1014. if (disp->vibrant_hue_property)
  1015. drm_object_attach_property(&connector->base,
  1016. disp->vibrant_hue_property,
  1017. 90);
  1018. if (disp->color_vibrance_property)
  1019. drm_object_attach_property(&connector->base,
  1020. disp->color_vibrance_property,
  1021. 150);
  1022. switch (nv_connector->type) {
  1023. case DCB_CONNECTOR_VGA:
  1024. if (nv_device(drm->device)->card_type >= NV_50) {
  1025. drm_object_attach_property(&connector->base,
  1026. dev->mode_config.scaling_mode_property,
  1027. nv_connector->scaling_mode);
  1028. }
  1029. /* fall-through */
  1030. case DCB_CONNECTOR_TV_0:
  1031. case DCB_CONNECTOR_TV_1:
  1032. case DCB_CONNECTOR_TV_3:
  1033. nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
  1034. break;
  1035. default:
  1036. nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
  1037. drm_object_attach_property(&connector->base,
  1038. dev->mode_config.scaling_mode_property,
  1039. nv_connector->scaling_mode);
  1040. if (disp->dithering_mode) {
  1041. nv_connector->dithering_mode = DITHERING_MODE_AUTO;
  1042. drm_object_attach_property(&connector->base,
  1043. disp->dithering_mode,
  1044. nv_connector->dithering_mode);
  1045. }
  1046. if (disp->dithering_depth) {
  1047. nv_connector->dithering_depth = DITHERING_DEPTH_AUTO;
  1048. drm_object_attach_property(&connector->base,
  1049. disp->dithering_depth,
  1050. nv_connector->dithering_depth);
  1051. }
  1052. break;
  1053. }
  1054. ret = nouveau_event_new(pdisp->hpd, NVKM_HPD, index,
  1055. nouveau_connector_hotplug,
  1056. nv_connector, &nv_connector->hpd);
  1057. if (ret)
  1058. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  1059. else
  1060. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1061. INIT_WORK(&nv_connector->work, nouveau_connector_hotplug_work);
  1062. drm_sysfs_connector_add(connector);
  1063. return connector;
  1064. }