amdgpu_connectors.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_edid.h>
  28. #include <drm/drm_crtc_helper.h>
  29. #include <drm/drm_fb_helper.h>
  30. #include <drm/amdgpu_drm.h>
  31. #include "amdgpu.h"
  32. #include "atom.h"
  33. #include "atombios_encoders.h"
  34. #include "atombios_dp.h"
  35. #include "amdgpu_connectors.h"
  36. #include "amdgpu_i2c.h"
  37. #include <linux/pm_runtime.h>
  38. void amdgpu_connector_hotplug(struct drm_connector *connector)
  39. {
  40. struct drm_device *dev = connector->dev;
  41. struct amdgpu_device *adev = dev->dev_private;
  42. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  43. /* bail if the connector does not have hpd pin, e.g.,
  44. * VGA, TV, etc.
  45. */
  46. if (amdgpu_connector->hpd.hpd == AMDGPU_HPD_NONE)
  47. return;
  48. amdgpu_display_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
  49. /* if the connector is already off, don't turn it back on */
  50. if (connector->dpms != DRM_MODE_DPMS_ON)
  51. return;
  52. /* just deal with DP (not eDP) here. */
  53. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
  54. struct amdgpu_connector_atom_dig *dig_connector =
  55. amdgpu_connector->con_priv;
  56. /* if existing sink type was not DP no need to retrain */
  57. if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
  58. return;
  59. /* first get sink type as it may be reset after (un)plug */
  60. dig_connector->dp_sink_type = amdgpu_atombios_dp_get_sinktype(amdgpu_connector);
  61. /* don't do anything if sink is not display port, i.e.,
  62. * passive dp->(dvi|hdmi) adaptor
  63. */
  64. if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT &&
  65. amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd) &&
  66. amdgpu_atombios_dp_needs_link_train(amdgpu_connector)) {
  67. /* Don't start link training before we have the DPCD */
  68. if (amdgpu_atombios_dp_get_dpcd(amdgpu_connector))
  69. return;
  70. /* Turn the connector off and back on immediately, which
  71. * will trigger link training
  72. */
  73. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  74. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  75. }
  76. }
  77. }
  78. static void amdgpu_connector_property_change_mode(struct drm_encoder *encoder)
  79. {
  80. struct drm_crtc *crtc = encoder->crtc;
  81. if (crtc && crtc->enabled) {
  82. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  83. crtc->x, crtc->y, crtc->primary->fb);
  84. }
  85. }
  86. int amdgpu_connector_get_monitor_bpc(struct drm_connector *connector)
  87. {
  88. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  89. struct amdgpu_connector_atom_dig *dig_connector;
  90. int bpc = 8;
  91. unsigned mode_clock, max_tmds_clock;
  92. switch (connector->connector_type) {
  93. case DRM_MODE_CONNECTOR_DVII:
  94. case DRM_MODE_CONNECTOR_HDMIB:
  95. if (amdgpu_connector->use_digital) {
  96. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  97. if (connector->display_info.bpc)
  98. bpc = connector->display_info.bpc;
  99. }
  100. }
  101. break;
  102. case DRM_MODE_CONNECTOR_DVID:
  103. case DRM_MODE_CONNECTOR_HDMIA:
  104. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  105. if (connector->display_info.bpc)
  106. bpc = connector->display_info.bpc;
  107. }
  108. break;
  109. case DRM_MODE_CONNECTOR_DisplayPort:
  110. dig_connector = amdgpu_connector->con_priv;
  111. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  112. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
  113. drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  114. if (connector->display_info.bpc)
  115. bpc = connector->display_info.bpc;
  116. }
  117. break;
  118. case DRM_MODE_CONNECTOR_eDP:
  119. case DRM_MODE_CONNECTOR_LVDS:
  120. if (connector->display_info.bpc)
  121. bpc = connector->display_info.bpc;
  122. else {
  123. const struct drm_connector_helper_funcs *connector_funcs =
  124. connector->helper_private;
  125. struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
  126. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  127. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  128. if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
  129. bpc = 6;
  130. else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
  131. bpc = 8;
  132. }
  133. break;
  134. }
  135. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  136. /*
  137. * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
  138. * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
  139. * 12 bpc is always supported on hdmi deep color sinks, as this is
  140. * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
  141. */
  142. if (bpc > 12) {
  143. DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
  144. connector->name, bpc);
  145. bpc = 12;
  146. }
  147. /* Any defined maximum tmds clock limit we must not exceed? */
  148. if (connector->display_info.max_tmds_clock > 0) {
  149. /* mode_clock is clock in kHz for mode to be modeset on this connector */
  150. mode_clock = amdgpu_connector->pixelclock_for_modeset;
  151. /* Maximum allowable input clock in kHz */
  152. max_tmds_clock = connector->display_info.max_tmds_clock;
  153. DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
  154. connector->name, mode_clock, max_tmds_clock);
  155. /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
  156. if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
  157. if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
  158. (mode_clock * 5/4 <= max_tmds_clock))
  159. bpc = 10;
  160. else
  161. bpc = 8;
  162. DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
  163. connector->name, bpc);
  164. }
  165. if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
  166. bpc = 8;
  167. DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
  168. connector->name, bpc);
  169. }
  170. } else if (bpc > 8) {
  171. /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
  172. DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
  173. connector->name);
  174. bpc = 8;
  175. }
  176. }
  177. if ((amdgpu_deep_color == 0) && (bpc > 8)) {
  178. DRM_DEBUG("%s: Deep color disabled. Set amdgpu module param deep_color=1 to enable.\n",
  179. connector->name);
  180. bpc = 8;
  181. }
  182. DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
  183. connector->name, connector->display_info.bpc, bpc);
  184. return bpc;
  185. }
  186. static void
  187. amdgpu_connector_update_scratch_regs(struct drm_connector *connector,
  188. enum drm_connector_status status)
  189. {
  190. struct drm_encoder *best_encoder = NULL;
  191. struct drm_encoder *encoder = NULL;
  192. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  193. bool connected;
  194. int i;
  195. best_encoder = connector_funcs->best_encoder(connector);
  196. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  197. if (connector->encoder_ids[i] == 0)
  198. break;
  199. encoder = drm_encoder_find(connector->dev, NULL,
  200. connector->encoder_ids[i]);
  201. if (!encoder)
  202. continue;
  203. if ((encoder == best_encoder) && (status == connector_status_connected))
  204. connected = true;
  205. else
  206. connected = false;
  207. amdgpu_atombios_encoder_set_bios_scratch_regs(connector, encoder, connected);
  208. }
  209. }
  210. static struct drm_encoder *
  211. amdgpu_connector_find_encoder(struct drm_connector *connector,
  212. int encoder_type)
  213. {
  214. struct drm_encoder *encoder;
  215. int i;
  216. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  217. if (connector->encoder_ids[i] == 0)
  218. break;
  219. encoder = drm_encoder_find(connector->dev, NULL,
  220. connector->encoder_ids[i]);
  221. if (!encoder)
  222. continue;
  223. if (encoder->encoder_type == encoder_type)
  224. return encoder;
  225. }
  226. return NULL;
  227. }
  228. struct edid *amdgpu_connector_edid(struct drm_connector *connector)
  229. {
  230. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  231. struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
  232. if (amdgpu_connector->edid) {
  233. return amdgpu_connector->edid;
  234. } else if (edid_blob) {
  235. struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
  236. if (edid)
  237. amdgpu_connector->edid = edid;
  238. }
  239. return amdgpu_connector->edid;
  240. }
  241. static struct edid *
  242. amdgpu_connector_get_hardcoded_edid(struct amdgpu_device *adev)
  243. {
  244. struct edid *edid;
  245. if (adev->mode_info.bios_hardcoded_edid) {
  246. edid = kmalloc(adev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
  247. if (edid) {
  248. memcpy((unsigned char *)edid,
  249. (unsigned char *)adev->mode_info.bios_hardcoded_edid,
  250. adev->mode_info.bios_hardcoded_edid_size);
  251. return edid;
  252. }
  253. }
  254. return NULL;
  255. }
  256. static void amdgpu_connector_get_edid(struct drm_connector *connector)
  257. {
  258. struct drm_device *dev = connector->dev;
  259. struct amdgpu_device *adev = dev->dev_private;
  260. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  261. if (amdgpu_connector->edid)
  262. return;
  263. /* on hw with routers, select right port */
  264. if (amdgpu_connector->router.ddc_valid)
  265. amdgpu_i2c_router_select_ddc_port(amdgpu_connector);
  266. if ((amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  267. ENCODER_OBJECT_ID_NONE) &&
  268. amdgpu_connector->ddc_bus->has_aux) {
  269. amdgpu_connector->edid = drm_get_edid(connector,
  270. &amdgpu_connector->ddc_bus->aux.ddc);
  271. } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
  272. (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
  273. struct amdgpu_connector_atom_dig *dig = amdgpu_connector->con_priv;
  274. if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
  275. dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
  276. amdgpu_connector->ddc_bus->has_aux)
  277. amdgpu_connector->edid = drm_get_edid(connector,
  278. &amdgpu_connector->ddc_bus->aux.ddc);
  279. else if (amdgpu_connector->ddc_bus)
  280. amdgpu_connector->edid = drm_get_edid(connector,
  281. &amdgpu_connector->ddc_bus->adapter);
  282. } else if (amdgpu_connector->ddc_bus) {
  283. amdgpu_connector->edid = drm_get_edid(connector,
  284. &amdgpu_connector->ddc_bus->adapter);
  285. }
  286. if (!amdgpu_connector->edid) {
  287. /* some laptops provide a hardcoded edid in rom for LCDs */
  288. if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
  289. (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
  290. amdgpu_connector->edid = amdgpu_connector_get_hardcoded_edid(adev);
  291. }
  292. }
  293. static void amdgpu_connector_free_edid(struct drm_connector *connector)
  294. {
  295. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  296. if (amdgpu_connector->edid) {
  297. kfree(amdgpu_connector->edid);
  298. amdgpu_connector->edid = NULL;
  299. }
  300. }
  301. static int amdgpu_connector_ddc_get_modes(struct drm_connector *connector)
  302. {
  303. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  304. int ret;
  305. if (amdgpu_connector->edid) {
  306. drm_mode_connector_update_edid_property(connector, amdgpu_connector->edid);
  307. ret = drm_add_edid_modes(connector, amdgpu_connector->edid);
  308. drm_edid_to_eld(connector, amdgpu_connector->edid);
  309. return ret;
  310. }
  311. drm_mode_connector_update_edid_property(connector, NULL);
  312. return 0;
  313. }
  314. static struct drm_encoder *
  315. amdgpu_connector_best_single_encoder(struct drm_connector *connector)
  316. {
  317. int enc_id = connector->encoder_ids[0];
  318. /* pick the encoder ids */
  319. if (enc_id)
  320. return drm_encoder_find(connector->dev, NULL, enc_id);
  321. return NULL;
  322. }
  323. static void amdgpu_get_native_mode(struct drm_connector *connector)
  324. {
  325. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  326. struct amdgpu_encoder *amdgpu_encoder;
  327. if (encoder == NULL)
  328. return;
  329. amdgpu_encoder = to_amdgpu_encoder(encoder);
  330. if (!list_empty(&connector->probed_modes)) {
  331. struct drm_display_mode *preferred_mode =
  332. list_first_entry(&connector->probed_modes,
  333. struct drm_display_mode, head);
  334. amdgpu_encoder->native_mode = *preferred_mode;
  335. } else {
  336. amdgpu_encoder->native_mode.clock = 0;
  337. }
  338. }
  339. static struct drm_display_mode *
  340. amdgpu_connector_lcd_native_mode(struct drm_encoder *encoder)
  341. {
  342. struct drm_device *dev = encoder->dev;
  343. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  344. struct drm_display_mode *mode = NULL;
  345. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  346. if (native_mode->hdisplay != 0 &&
  347. native_mode->vdisplay != 0 &&
  348. native_mode->clock != 0) {
  349. mode = drm_mode_duplicate(dev, native_mode);
  350. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  351. drm_mode_set_name(mode);
  352. DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
  353. } else if (native_mode->hdisplay != 0 &&
  354. native_mode->vdisplay != 0) {
  355. /* mac laptops without an edid */
  356. /* Note that this is not necessarily the exact panel mode,
  357. * but an approximation based on the cvt formula. For these
  358. * systems we should ideally read the mode info out of the
  359. * registers or add a mode table, but this works and is much
  360. * simpler.
  361. */
  362. mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
  363. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  364. DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
  365. }
  366. return mode;
  367. }
  368. static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
  369. struct drm_connector *connector)
  370. {
  371. struct drm_device *dev = encoder->dev;
  372. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  373. struct drm_display_mode *mode = NULL;
  374. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  375. int i;
  376. static const struct mode_size {
  377. int w;
  378. int h;
  379. } common_modes[17] = {
  380. { 640, 480},
  381. { 720, 480},
  382. { 800, 600},
  383. { 848, 480},
  384. {1024, 768},
  385. {1152, 768},
  386. {1280, 720},
  387. {1280, 800},
  388. {1280, 854},
  389. {1280, 960},
  390. {1280, 1024},
  391. {1440, 900},
  392. {1400, 1050},
  393. {1680, 1050},
  394. {1600, 1200},
  395. {1920, 1080},
  396. {1920, 1200}
  397. };
  398. for (i = 0; i < 17; i++) {
  399. if (amdgpu_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  400. if (common_modes[i].w > 1024 ||
  401. common_modes[i].h > 768)
  402. continue;
  403. }
  404. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  405. if (common_modes[i].w > native_mode->hdisplay ||
  406. common_modes[i].h > native_mode->vdisplay ||
  407. (common_modes[i].w == native_mode->hdisplay &&
  408. common_modes[i].h == native_mode->vdisplay))
  409. continue;
  410. }
  411. if (common_modes[i].w < 320 || common_modes[i].h < 200)
  412. continue;
  413. mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
  414. drm_mode_probed_add(connector, mode);
  415. }
  416. }
  417. static int amdgpu_connector_set_property(struct drm_connector *connector,
  418. struct drm_property *property,
  419. uint64_t val)
  420. {
  421. struct drm_device *dev = connector->dev;
  422. struct amdgpu_device *adev = dev->dev_private;
  423. struct drm_encoder *encoder;
  424. struct amdgpu_encoder *amdgpu_encoder;
  425. if (property == adev->mode_info.coherent_mode_property) {
  426. struct amdgpu_encoder_atom_dig *dig;
  427. bool new_coherent_mode;
  428. /* need to find digital encoder on connector */
  429. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  430. if (!encoder)
  431. return 0;
  432. amdgpu_encoder = to_amdgpu_encoder(encoder);
  433. if (!amdgpu_encoder->enc_priv)
  434. return 0;
  435. dig = amdgpu_encoder->enc_priv;
  436. new_coherent_mode = val ? true : false;
  437. if (dig->coherent_mode != new_coherent_mode) {
  438. dig->coherent_mode = new_coherent_mode;
  439. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  440. }
  441. }
  442. if (property == adev->mode_info.audio_property) {
  443. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  444. /* need to find digital encoder on connector */
  445. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  446. if (!encoder)
  447. return 0;
  448. amdgpu_encoder = to_amdgpu_encoder(encoder);
  449. if (amdgpu_connector->audio != val) {
  450. amdgpu_connector->audio = val;
  451. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  452. }
  453. }
  454. if (property == adev->mode_info.dither_property) {
  455. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  456. /* need to find digital encoder on connector */
  457. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  458. if (!encoder)
  459. return 0;
  460. amdgpu_encoder = to_amdgpu_encoder(encoder);
  461. if (amdgpu_connector->dither != val) {
  462. amdgpu_connector->dither = val;
  463. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  464. }
  465. }
  466. if (property == adev->mode_info.underscan_property) {
  467. /* need to find digital encoder on connector */
  468. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  469. if (!encoder)
  470. return 0;
  471. amdgpu_encoder = to_amdgpu_encoder(encoder);
  472. if (amdgpu_encoder->underscan_type != val) {
  473. amdgpu_encoder->underscan_type = val;
  474. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  475. }
  476. }
  477. if (property == adev->mode_info.underscan_hborder_property) {
  478. /* need to find digital encoder on connector */
  479. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  480. if (!encoder)
  481. return 0;
  482. amdgpu_encoder = to_amdgpu_encoder(encoder);
  483. if (amdgpu_encoder->underscan_hborder != val) {
  484. amdgpu_encoder->underscan_hborder = val;
  485. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  486. }
  487. }
  488. if (property == adev->mode_info.underscan_vborder_property) {
  489. /* need to find digital encoder on connector */
  490. encoder = amdgpu_connector_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  491. if (!encoder)
  492. return 0;
  493. amdgpu_encoder = to_amdgpu_encoder(encoder);
  494. if (amdgpu_encoder->underscan_vborder != val) {
  495. amdgpu_encoder->underscan_vborder = val;
  496. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  497. }
  498. }
  499. if (property == adev->mode_info.load_detect_property) {
  500. struct amdgpu_connector *amdgpu_connector =
  501. to_amdgpu_connector(connector);
  502. if (val == 0)
  503. amdgpu_connector->dac_load_detect = false;
  504. else
  505. amdgpu_connector->dac_load_detect = true;
  506. }
  507. if (property == dev->mode_config.scaling_mode_property) {
  508. enum amdgpu_rmx_type rmx_type;
  509. if (connector->encoder) {
  510. amdgpu_encoder = to_amdgpu_encoder(connector->encoder);
  511. } else {
  512. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  513. amdgpu_encoder = to_amdgpu_encoder(connector_funcs->best_encoder(connector));
  514. }
  515. switch (val) {
  516. default:
  517. case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
  518. case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
  519. case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
  520. case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
  521. }
  522. if (amdgpu_encoder->rmx_type == rmx_type)
  523. return 0;
  524. if ((rmx_type != DRM_MODE_SCALE_NONE) &&
  525. (amdgpu_encoder->native_mode.clock == 0))
  526. return 0;
  527. amdgpu_encoder->rmx_type = rmx_type;
  528. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  529. }
  530. return 0;
  531. }
  532. static void
  533. amdgpu_connector_fixup_lcd_native_mode(struct drm_encoder *encoder,
  534. struct drm_connector *connector)
  535. {
  536. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  537. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  538. struct drm_display_mode *t, *mode;
  539. /* If the EDID preferred mode doesn't match the native mode, use it */
  540. list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
  541. if (mode->type & DRM_MODE_TYPE_PREFERRED) {
  542. if (mode->hdisplay != native_mode->hdisplay ||
  543. mode->vdisplay != native_mode->vdisplay)
  544. memcpy(native_mode, mode, sizeof(*mode));
  545. }
  546. }
  547. /* Try to get native mode details from EDID if necessary */
  548. if (!native_mode->clock) {
  549. list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
  550. if (mode->hdisplay == native_mode->hdisplay &&
  551. mode->vdisplay == native_mode->vdisplay) {
  552. *native_mode = *mode;
  553. drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
  554. DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
  555. break;
  556. }
  557. }
  558. }
  559. if (!native_mode->clock) {
  560. DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
  561. amdgpu_encoder->rmx_type = RMX_OFF;
  562. }
  563. }
  564. static int amdgpu_connector_lvds_get_modes(struct drm_connector *connector)
  565. {
  566. struct drm_encoder *encoder;
  567. int ret = 0;
  568. struct drm_display_mode *mode;
  569. amdgpu_connector_get_edid(connector);
  570. ret = amdgpu_connector_ddc_get_modes(connector);
  571. if (ret > 0) {
  572. encoder = amdgpu_connector_best_single_encoder(connector);
  573. if (encoder) {
  574. amdgpu_connector_fixup_lcd_native_mode(encoder, connector);
  575. /* add scaled modes */
  576. amdgpu_connector_add_common_modes(encoder, connector);
  577. }
  578. return ret;
  579. }
  580. encoder = amdgpu_connector_best_single_encoder(connector);
  581. if (!encoder)
  582. return 0;
  583. /* we have no EDID modes */
  584. mode = amdgpu_connector_lcd_native_mode(encoder);
  585. if (mode) {
  586. ret = 1;
  587. drm_mode_probed_add(connector, mode);
  588. /* add the width/height from vbios tables if available */
  589. connector->display_info.width_mm = mode->width_mm;
  590. connector->display_info.height_mm = mode->height_mm;
  591. /* add scaled modes */
  592. amdgpu_connector_add_common_modes(encoder, connector);
  593. }
  594. return ret;
  595. }
  596. static int amdgpu_connector_lvds_mode_valid(struct drm_connector *connector,
  597. struct drm_display_mode *mode)
  598. {
  599. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  600. if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
  601. return MODE_PANEL;
  602. if (encoder) {
  603. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  604. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  605. /* AVIVO hardware supports downscaling modes larger than the panel
  606. * to the panel size, but I'm not sure this is desirable.
  607. */
  608. if ((mode->hdisplay > native_mode->hdisplay) ||
  609. (mode->vdisplay > native_mode->vdisplay))
  610. return MODE_PANEL;
  611. /* if scaling is disabled, block non-native modes */
  612. if (amdgpu_encoder->rmx_type == RMX_OFF) {
  613. if ((mode->hdisplay != native_mode->hdisplay) ||
  614. (mode->vdisplay != native_mode->vdisplay))
  615. return MODE_PANEL;
  616. }
  617. }
  618. return MODE_OK;
  619. }
  620. static enum drm_connector_status
  621. amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
  622. {
  623. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  624. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  625. enum drm_connector_status ret = connector_status_disconnected;
  626. int r;
  627. if (!drm_kms_helper_is_poll_worker()) {
  628. r = pm_runtime_get_sync(connector->dev->dev);
  629. if (r < 0) {
  630. pm_runtime_put_autosuspend(connector->dev->dev);
  631. return connector_status_disconnected;
  632. }
  633. }
  634. if (encoder) {
  635. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  636. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  637. /* check if panel is valid */
  638. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  639. ret = connector_status_connected;
  640. }
  641. /* check for edid as well */
  642. amdgpu_connector_get_edid(connector);
  643. if (amdgpu_connector->edid)
  644. ret = connector_status_connected;
  645. /* check acpi lid status ??? */
  646. amdgpu_connector_update_scratch_regs(connector, ret);
  647. if (!drm_kms_helper_is_poll_worker()) {
  648. pm_runtime_mark_last_busy(connector->dev->dev);
  649. pm_runtime_put_autosuspend(connector->dev->dev);
  650. }
  651. return ret;
  652. }
  653. static void amdgpu_connector_unregister(struct drm_connector *connector)
  654. {
  655. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  656. if (amdgpu_connector->ddc_bus && amdgpu_connector->ddc_bus->has_aux) {
  657. drm_dp_aux_unregister(&amdgpu_connector->ddc_bus->aux);
  658. amdgpu_connector->ddc_bus->has_aux = false;
  659. }
  660. }
  661. static void amdgpu_connector_destroy(struct drm_connector *connector)
  662. {
  663. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  664. amdgpu_connector_free_edid(connector);
  665. kfree(amdgpu_connector->con_priv);
  666. drm_connector_unregister(connector);
  667. drm_connector_cleanup(connector);
  668. kfree(connector);
  669. }
  670. static int amdgpu_connector_set_lcd_property(struct drm_connector *connector,
  671. struct drm_property *property,
  672. uint64_t value)
  673. {
  674. struct drm_device *dev = connector->dev;
  675. struct amdgpu_encoder *amdgpu_encoder;
  676. enum amdgpu_rmx_type rmx_type;
  677. DRM_DEBUG_KMS("\n");
  678. if (property != dev->mode_config.scaling_mode_property)
  679. return 0;
  680. if (connector->encoder)
  681. amdgpu_encoder = to_amdgpu_encoder(connector->encoder);
  682. else {
  683. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  684. amdgpu_encoder = to_amdgpu_encoder(connector_funcs->best_encoder(connector));
  685. }
  686. switch (value) {
  687. case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
  688. case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
  689. case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
  690. default:
  691. case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
  692. }
  693. if (amdgpu_encoder->rmx_type == rmx_type)
  694. return 0;
  695. amdgpu_encoder->rmx_type = rmx_type;
  696. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  697. return 0;
  698. }
  699. static const struct drm_connector_helper_funcs amdgpu_connector_lvds_helper_funcs = {
  700. .get_modes = amdgpu_connector_lvds_get_modes,
  701. .mode_valid = amdgpu_connector_lvds_mode_valid,
  702. .best_encoder = amdgpu_connector_best_single_encoder,
  703. };
  704. static const struct drm_connector_funcs amdgpu_connector_lvds_funcs = {
  705. .dpms = drm_helper_connector_dpms,
  706. .detect = amdgpu_connector_lvds_detect,
  707. .fill_modes = drm_helper_probe_single_connector_modes,
  708. .early_unregister = amdgpu_connector_unregister,
  709. .destroy = amdgpu_connector_destroy,
  710. .set_property = amdgpu_connector_set_lcd_property,
  711. };
  712. static int amdgpu_connector_vga_get_modes(struct drm_connector *connector)
  713. {
  714. int ret;
  715. amdgpu_connector_get_edid(connector);
  716. ret = amdgpu_connector_ddc_get_modes(connector);
  717. return ret;
  718. }
  719. static int amdgpu_connector_vga_mode_valid(struct drm_connector *connector,
  720. struct drm_display_mode *mode)
  721. {
  722. struct drm_device *dev = connector->dev;
  723. struct amdgpu_device *adev = dev->dev_private;
  724. /* XXX check mode bandwidth */
  725. if ((mode->clock / 10) > adev->clock.max_pixel_clock)
  726. return MODE_CLOCK_HIGH;
  727. return MODE_OK;
  728. }
  729. static enum drm_connector_status
  730. amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
  731. {
  732. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  733. struct drm_encoder *encoder;
  734. const struct drm_encoder_helper_funcs *encoder_funcs;
  735. bool dret = false;
  736. enum drm_connector_status ret = connector_status_disconnected;
  737. int r;
  738. if (!drm_kms_helper_is_poll_worker()) {
  739. r = pm_runtime_get_sync(connector->dev->dev);
  740. if (r < 0) {
  741. pm_runtime_put_autosuspend(connector->dev->dev);
  742. return connector_status_disconnected;
  743. }
  744. }
  745. encoder = amdgpu_connector_best_single_encoder(connector);
  746. if (!encoder)
  747. ret = connector_status_disconnected;
  748. if (amdgpu_connector->ddc_bus)
  749. dret = amdgpu_ddc_probe(amdgpu_connector, false);
  750. if (dret) {
  751. amdgpu_connector->detected_by_load = false;
  752. amdgpu_connector_free_edid(connector);
  753. amdgpu_connector_get_edid(connector);
  754. if (!amdgpu_connector->edid) {
  755. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  756. connector->name);
  757. ret = connector_status_connected;
  758. } else {
  759. amdgpu_connector->use_digital =
  760. !!(amdgpu_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  761. /* some oems have boards with separate digital and analog connectors
  762. * with a shared ddc line (often vga + hdmi)
  763. */
  764. if (amdgpu_connector->use_digital && amdgpu_connector->shared_ddc) {
  765. amdgpu_connector_free_edid(connector);
  766. ret = connector_status_disconnected;
  767. } else {
  768. ret = connector_status_connected;
  769. }
  770. }
  771. } else {
  772. /* if we aren't forcing don't do destructive polling */
  773. if (!force) {
  774. /* only return the previous status if we last
  775. * detected a monitor via load.
  776. */
  777. if (amdgpu_connector->detected_by_load)
  778. ret = connector->status;
  779. goto out;
  780. }
  781. if (amdgpu_connector->dac_load_detect && encoder) {
  782. encoder_funcs = encoder->helper_private;
  783. ret = encoder_funcs->detect(encoder, connector);
  784. if (ret != connector_status_disconnected)
  785. amdgpu_connector->detected_by_load = true;
  786. }
  787. }
  788. amdgpu_connector_update_scratch_regs(connector, ret);
  789. out:
  790. if (!drm_kms_helper_is_poll_worker()) {
  791. pm_runtime_mark_last_busy(connector->dev->dev);
  792. pm_runtime_put_autosuspend(connector->dev->dev);
  793. }
  794. return ret;
  795. }
  796. static const struct drm_connector_helper_funcs amdgpu_connector_vga_helper_funcs = {
  797. .get_modes = amdgpu_connector_vga_get_modes,
  798. .mode_valid = amdgpu_connector_vga_mode_valid,
  799. .best_encoder = amdgpu_connector_best_single_encoder,
  800. };
  801. static const struct drm_connector_funcs amdgpu_connector_vga_funcs = {
  802. .dpms = drm_helper_connector_dpms,
  803. .detect = amdgpu_connector_vga_detect,
  804. .fill_modes = drm_helper_probe_single_connector_modes,
  805. .early_unregister = amdgpu_connector_unregister,
  806. .destroy = amdgpu_connector_destroy,
  807. .set_property = amdgpu_connector_set_property,
  808. };
  809. static bool
  810. amdgpu_connector_check_hpd_status_unchanged(struct drm_connector *connector)
  811. {
  812. struct drm_device *dev = connector->dev;
  813. struct amdgpu_device *adev = dev->dev_private;
  814. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  815. enum drm_connector_status status;
  816. if (amdgpu_connector->hpd.hpd != AMDGPU_HPD_NONE) {
  817. if (amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd))
  818. status = connector_status_connected;
  819. else
  820. status = connector_status_disconnected;
  821. if (connector->status == status)
  822. return true;
  823. }
  824. return false;
  825. }
  826. /*
  827. * DVI is complicated
  828. * Do a DDC probe, if DDC probe passes, get the full EDID so
  829. * we can do analog/digital monitor detection at this point.
  830. * If the monitor is an analog monitor or we got no DDC,
  831. * we need to find the DAC encoder object for this connector.
  832. * If we got no DDC, we do load detection on the DAC encoder object.
  833. * If we got analog DDC or load detection passes on the DAC encoder
  834. * we have to check if this analog encoder is shared with anyone else (TV)
  835. * if its shared we have to set the other connector to disconnected.
  836. */
  837. static enum drm_connector_status
  838. amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)
  839. {
  840. struct drm_device *dev = connector->dev;
  841. struct amdgpu_device *adev = dev->dev_private;
  842. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  843. struct drm_encoder *encoder = NULL;
  844. const struct drm_encoder_helper_funcs *encoder_funcs;
  845. int i, r;
  846. enum drm_connector_status ret = connector_status_disconnected;
  847. bool dret = false, broken_edid = false;
  848. if (!drm_kms_helper_is_poll_worker()) {
  849. r = pm_runtime_get_sync(connector->dev->dev);
  850. if (r < 0) {
  851. pm_runtime_put_autosuspend(connector->dev->dev);
  852. return connector_status_disconnected;
  853. }
  854. }
  855. if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
  856. ret = connector->status;
  857. goto exit;
  858. }
  859. if (amdgpu_connector->ddc_bus)
  860. dret = amdgpu_ddc_probe(amdgpu_connector, false);
  861. if (dret) {
  862. amdgpu_connector->detected_by_load = false;
  863. amdgpu_connector_free_edid(connector);
  864. amdgpu_connector_get_edid(connector);
  865. if (!amdgpu_connector->edid) {
  866. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  867. connector->name);
  868. ret = connector_status_connected;
  869. broken_edid = true; /* defer use_digital to later */
  870. } else {
  871. amdgpu_connector->use_digital =
  872. !!(amdgpu_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  873. /* some oems have boards with separate digital and analog connectors
  874. * with a shared ddc line (often vga + hdmi)
  875. */
  876. if ((!amdgpu_connector->use_digital) && amdgpu_connector->shared_ddc) {
  877. amdgpu_connector_free_edid(connector);
  878. ret = connector_status_disconnected;
  879. } else {
  880. ret = connector_status_connected;
  881. }
  882. /* This gets complicated. We have boards with VGA + HDMI with a
  883. * shared DDC line and we have boards with DVI-D + HDMI with a shared
  884. * DDC line. The latter is more complex because with DVI<->HDMI adapters
  885. * you don't really know what's connected to which port as both are digital.
  886. */
  887. if (amdgpu_connector->shared_ddc && (ret == connector_status_connected)) {
  888. struct drm_connector *list_connector;
  889. struct amdgpu_connector *list_amdgpu_connector;
  890. list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
  891. if (connector == list_connector)
  892. continue;
  893. list_amdgpu_connector = to_amdgpu_connector(list_connector);
  894. if (list_amdgpu_connector->shared_ddc &&
  895. (list_amdgpu_connector->ddc_bus->rec.i2c_id ==
  896. amdgpu_connector->ddc_bus->rec.i2c_id)) {
  897. /* cases where both connectors are digital */
  898. if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
  899. /* hpd is our only option in this case */
  900. if (!amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd)) {
  901. amdgpu_connector_free_edid(connector);
  902. ret = connector_status_disconnected;
  903. }
  904. }
  905. }
  906. }
  907. }
  908. }
  909. }
  910. if ((ret == connector_status_connected) && (amdgpu_connector->use_digital == true))
  911. goto out;
  912. /* DVI-D and HDMI-A are digital only */
  913. if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
  914. (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
  915. goto out;
  916. /* if we aren't forcing don't do destructive polling */
  917. if (!force) {
  918. /* only return the previous status if we last
  919. * detected a monitor via load.
  920. */
  921. if (amdgpu_connector->detected_by_load)
  922. ret = connector->status;
  923. goto out;
  924. }
  925. /* find analog encoder */
  926. if (amdgpu_connector->dac_load_detect) {
  927. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  928. if (connector->encoder_ids[i] == 0)
  929. break;
  930. encoder = drm_encoder_find(connector->dev, NULL,
  931. connector->encoder_ids[i]);
  932. if (!encoder)
  933. continue;
  934. if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
  935. encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
  936. continue;
  937. encoder_funcs = encoder->helper_private;
  938. if (encoder_funcs->detect) {
  939. if (!broken_edid) {
  940. if (ret != connector_status_connected) {
  941. /* deal with analog monitors without DDC */
  942. ret = encoder_funcs->detect(encoder, connector);
  943. if (ret == connector_status_connected) {
  944. amdgpu_connector->use_digital = false;
  945. }
  946. if (ret != connector_status_disconnected)
  947. amdgpu_connector->detected_by_load = true;
  948. }
  949. } else {
  950. enum drm_connector_status lret;
  951. /* assume digital unless load detected otherwise */
  952. amdgpu_connector->use_digital = true;
  953. lret = encoder_funcs->detect(encoder, connector);
  954. DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
  955. if (lret == connector_status_connected)
  956. amdgpu_connector->use_digital = false;
  957. }
  958. break;
  959. }
  960. }
  961. }
  962. out:
  963. /* updated in get modes as well since we need to know if it's analog or digital */
  964. amdgpu_connector_update_scratch_regs(connector, ret);
  965. exit:
  966. if (!drm_kms_helper_is_poll_worker()) {
  967. pm_runtime_mark_last_busy(connector->dev->dev);
  968. pm_runtime_put_autosuspend(connector->dev->dev);
  969. }
  970. return ret;
  971. }
  972. /* okay need to be smart in here about which encoder to pick */
  973. static struct drm_encoder *
  974. amdgpu_connector_dvi_encoder(struct drm_connector *connector)
  975. {
  976. int enc_id = connector->encoder_ids[0];
  977. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  978. struct drm_encoder *encoder;
  979. int i;
  980. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  981. if (connector->encoder_ids[i] == 0)
  982. break;
  983. encoder = drm_encoder_find(connector->dev, NULL,
  984. connector->encoder_ids[i]);
  985. if (!encoder)
  986. continue;
  987. if (amdgpu_connector->use_digital == true) {
  988. if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
  989. return encoder;
  990. } else {
  991. if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
  992. encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
  993. return encoder;
  994. }
  995. }
  996. /* see if we have a default encoder TODO */
  997. /* then check use digitial */
  998. /* pick the first one */
  999. if (enc_id)
  1000. return drm_encoder_find(connector->dev, NULL, enc_id);
  1001. return NULL;
  1002. }
  1003. static void amdgpu_connector_dvi_force(struct drm_connector *connector)
  1004. {
  1005. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1006. if (connector->force == DRM_FORCE_ON)
  1007. amdgpu_connector->use_digital = false;
  1008. if (connector->force == DRM_FORCE_ON_DIGITAL)
  1009. amdgpu_connector->use_digital = true;
  1010. }
  1011. static int amdgpu_connector_dvi_mode_valid(struct drm_connector *connector,
  1012. struct drm_display_mode *mode)
  1013. {
  1014. struct drm_device *dev = connector->dev;
  1015. struct amdgpu_device *adev = dev->dev_private;
  1016. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1017. /* XXX check mode bandwidth */
  1018. if (amdgpu_connector->use_digital && (mode->clock > 165000)) {
  1019. if ((amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
  1020. (amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
  1021. (amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B)) {
  1022. return MODE_OK;
  1023. } else if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  1024. /* HDMI 1.3+ supports max clock of 340 Mhz */
  1025. if (mode->clock > 340000)
  1026. return MODE_CLOCK_HIGH;
  1027. else
  1028. return MODE_OK;
  1029. } else {
  1030. return MODE_CLOCK_HIGH;
  1031. }
  1032. }
  1033. /* check against the max pixel clock */
  1034. if ((mode->clock / 10) > adev->clock.max_pixel_clock)
  1035. return MODE_CLOCK_HIGH;
  1036. return MODE_OK;
  1037. }
  1038. static const struct drm_connector_helper_funcs amdgpu_connector_dvi_helper_funcs = {
  1039. .get_modes = amdgpu_connector_vga_get_modes,
  1040. .mode_valid = amdgpu_connector_dvi_mode_valid,
  1041. .best_encoder = amdgpu_connector_dvi_encoder,
  1042. };
  1043. static const struct drm_connector_funcs amdgpu_connector_dvi_funcs = {
  1044. .dpms = drm_helper_connector_dpms,
  1045. .detect = amdgpu_connector_dvi_detect,
  1046. .fill_modes = drm_helper_probe_single_connector_modes,
  1047. .set_property = amdgpu_connector_set_property,
  1048. .early_unregister = amdgpu_connector_unregister,
  1049. .destroy = amdgpu_connector_destroy,
  1050. .force = amdgpu_connector_dvi_force,
  1051. };
  1052. static int amdgpu_connector_dp_get_modes(struct drm_connector *connector)
  1053. {
  1054. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1055. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1056. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1057. int ret;
  1058. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1059. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1060. struct drm_display_mode *mode;
  1061. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
  1062. if (!amdgpu_dig_connector->edp_on)
  1063. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1064. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1065. amdgpu_connector_get_edid(connector);
  1066. ret = amdgpu_connector_ddc_get_modes(connector);
  1067. if (!amdgpu_dig_connector->edp_on)
  1068. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1069. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1070. } else {
  1071. /* need to setup ddc on the bridge */
  1072. if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1073. ENCODER_OBJECT_ID_NONE) {
  1074. if (encoder)
  1075. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1076. }
  1077. amdgpu_connector_get_edid(connector);
  1078. ret = amdgpu_connector_ddc_get_modes(connector);
  1079. }
  1080. if (ret > 0) {
  1081. if (encoder) {
  1082. amdgpu_connector_fixup_lcd_native_mode(encoder, connector);
  1083. /* add scaled modes */
  1084. amdgpu_connector_add_common_modes(encoder, connector);
  1085. }
  1086. return ret;
  1087. }
  1088. if (!encoder)
  1089. return 0;
  1090. /* we have no EDID modes */
  1091. mode = amdgpu_connector_lcd_native_mode(encoder);
  1092. if (mode) {
  1093. ret = 1;
  1094. drm_mode_probed_add(connector, mode);
  1095. /* add the width/height from vbios tables if available */
  1096. connector->display_info.width_mm = mode->width_mm;
  1097. connector->display_info.height_mm = mode->height_mm;
  1098. /* add scaled modes */
  1099. amdgpu_connector_add_common_modes(encoder, connector);
  1100. }
  1101. } else {
  1102. /* need to setup ddc on the bridge */
  1103. if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1104. ENCODER_OBJECT_ID_NONE) {
  1105. if (encoder)
  1106. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1107. }
  1108. amdgpu_connector_get_edid(connector);
  1109. ret = amdgpu_connector_ddc_get_modes(connector);
  1110. amdgpu_get_native_mode(connector);
  1111. }
  1112. return ret;
  1113. }
  1114. u16 amdgpu_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
  1115. {
  1116. struct drm_encoder *encoder;
  1117. struct amdgpu_encoder *amdgpu_encoder;
  1118. int i;
  1119. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1120. if (connector->encoder_ids[i] == 0)
  1121. break;
  1122. encoder = drm_encoder_find(connector->dev, NULL,
  1123. connector->encoder_ids[i]);
  1124. if (!encoder)
  1125. continue;
  1126. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1127. switch (amdgpu_encoder->encoder_id) {
  1128. case ENCODER_OBJECT_ID_TRAVIS:
  1129. case ENCODER_OBJECT_ID_NUTMEG:
  1130. return amdgpu_encoder->encoder_id;
  1131. default:
  1132. break;
  1133. }
  1134. }
  1135. return ENCODER_OBJECT_ID_NONE;
  1136. }
  1137. static bool amdgpu_connector_encoder_is_hbr2(struct drm_connector *connector)
  1138. {
  1139. struct drm_encoder *encoder;
  1140. struct amdgpu_encoder *amdgpu_encoder;
  1141. int i;
  1142. bool found = false;
  1143. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1144. if (connector->encoder_ids[i] == 0)
  1145. break;
  1146. encoder = drm_encoder_find(connector->dev, NULL,
  1147. connector->encoder_ids[i]);
  1148. if (!encoder)
  1149. continue;
  1150. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1151. if (amdgpu_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
  1152. found = true;
  1153. }
  1154. return found;
  1155. }
  1156. bool amdgpu_connector_is_dp12_capable(struct drm_connector *connector)
  1157. {
  1158. struct drm_device *dev = connector->dev;
  1159. struct amdgpu_device *adev = dev->dev_private;
  1160. if ((adev->clock.default_dispclk >= 53900) &&
  1161. amdgpu_connector_encoder_is_hbr2(connector)) {
  1162. return true;
  1163. }
  1164. return false;
  1165. }
  1166. static enum drm_connector_status
  1167. amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
  1168. {
  1169. struct drm_device *dev = connector->dev;
  1170. struct amdgpu_device *adev = dev->dev_private;
  1171. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1172. enum drm_connector_status ret = connector_status_disconnected;
  1173. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1174. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1175. int r;
  1176. if (!drm_kms_helper_is_poll_worker()) {
  1177. r = pm_runtime_get_sync(connector->dev->dev);
  1178. if (r < 0) {
  1179. pm_runtime_put_autosuspend(connector->dev->dev);
  1180. return connector_status_disconnected;
  1181. }
  1182. }
  1183. if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
  1184. ret = connector->status;
  1185. goto out;
  1186. }
  1187. amdgpu_connector_free_edid(connector);
  1188. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1189. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1190. if (encoder) {
  1191. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1192. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  1193. /* check if panel is valid */
  1194. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  1195. ret = connector_status_connected;
  1196. }
  1197. /* eDP is always DP */
  1198. amdgpu_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1199. if (!amdgpu_dig_connector->edp_on)
  1200. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1201. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1202. if (!amdgpu_atombios_dp_get_dpcd(amdgpu_connector))
  1203. ret = connector_status_connected;
  1204. if (!amdgpu_dig_connector->edp_on)
  1205. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1206. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1207. } else if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1208. ENCODER_OBJECT_ID_NONE) {
  1209. /* DP bridges are always DP */
  1210. amdgpu_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1211. /* get the DPCD from the bridge */
  1212. amdgpu_atombios_dp_get_dpcd(amdgpu_connector);
  1213. if (encoder) {
  1214. /* setup ddc on the bridge */
  1215. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1216. /* bridge chips are always aux */
  1217. if (amdgpu_ddc_probe(amdgpu_connector, true)) /* try DDC */
  1218. ret = connector_status_connected;
  1219. else if (amdgpu_connector->dac_load_detect) { /* try load detection */
  1220. const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1221. ret = encoder_funcs->detect(encoder, connector);
  1222. }
  1223. }
  1224. } else {
  1225. amdgpu_dig_connector->dp_sink_type =
  1226. amdgpu_atombios_dp_get_sinktype(amdgpu_connector);
  1227. if (amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd)) {
  1228. ret = connector_status_connected;
  1229. if (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
  1230. amdgpu_atombios_dp_get_dpcd(amdgpu_connector);
  1231. } else {
  1232. if (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
  1233. if (!amdgpu_atombios_dp_get_dpcd(amdgpu_connector))
  1234. ret = connector_status_connected;
  1235. } else {
  1236. /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
  1237. if (amdgpu_ddc_probe(amdgpu_connector, false))
  1238. ret = connector_status_connected;
  1239. }
  1240. }
  1241. }
  1242. amdgpu_connector_update_scratch_regs(connector, ret);
  1243. out:
  1244. if (!drm_kms_helper_is_poll_worker()) {
  1245. pm_runtime_mark_last_busy(connector->dev->dev);
  1246. pm_runtime_put_autosuspend(connector->dev->dev);
  1247. }
  1248. return ret;
  1249. }
  1250. static int amdgpu_connector_dp_mode_valid(struct drm_connector *connector,
  1251. struct drm_display_mode *mode)
  1252. {
  1253. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1254. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1255. /* XXX check mode bandwidth */
  1256. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1257. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1258. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1259. if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
  1260. return MODE_PANEL;
  1261. if (encoder) {
  1262. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1263. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  1264. /* AVIVO hardware supports downscaling modes larger than the panel
  1265. * to the panel size, but I'm not sure this is desirable.
  1266. */
  1267. if ((mode->hdisplay > native_mode->hdisplay) ||
  1268. (mode->vdisplay > native_mode->vdisplay))
  1269. return MODE_PANEL;
  1270. /* if scaling is disabled, block non-native modes */
  1271. if (amdgpu_encoder->rmx_type == RMX_OFF) {
  1272. if ((mode->hdisplay != native_mode->hdisplay) ||
  1273. (mode->vdisplay != native_mode->vdisplay))
  1274. return MODE_PANEL;
  1275. }
  1276. }
  1277. return MODE_OK;
  1278. } else {
  1279. if ((amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  1280. (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
  1281. return amdgpu_atombios_dp_mode_valid_helper(connector, mode);
  1282. } else {
  1283. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  1284. /* HDMI 1.3+ supports max clock of 340 Mhz */
  1285. if (mode->clock > 340000)
  1286. return MODE_CLOCK_HIGH;
  1287. } else {
  1288. if (mode->clock > 165000)
  1289. return MODE_CLOCK_HIGH;
  1290. }
  1291. }
  1292. }
  1293. return MODE_OK;
  1294. }
  1295. static const struct drm_connector_helper_funcs amdgpu_connector_dp_helper_funcs = {
  1296. .get_modes = amdgpu_connector_dp_get_modes,
  1297. .mode_valid = amdgpu_connector_dp_mode_valid,
  1298. .best_encoder = amdgpu_connector_dvi_encoder,
  1299. };
  1300. static const struct drm_connector_funcs amdgpu_connector_dp_funcs = {
  1301. .dpms = drm_helper_connector_dpms,
  1302. .detect = amdgpu_connector_dp_detect,
  1303. .fill_modes = drm_helper_probe_single_connector_modes,
  1304. .set_property = amdgpu_connector_set_property,
  1305. .early_unregister = amdgpu_connector_unregister,
  1306. .destroy = amdgpu_connector_destroy,
  1307. .force = amdgpu_connector_dvi_force,
  1308. };
  1309. static const struct drm_connector_funcs amdgpu_connector_edp_funcs = {
  1310. .dpms = drm_helper_connector_dpms,
  1311. .detect = amdgpu_connector_dp_detect,
  1312. .fill_modes = drm_helper_probe_single_connector_modes,
  1313. .set_property = amdgpu_connector_set_lcd_property,
  1314. .early_unregister = amdgpu_connector_unregister,
  1315. .destroy = amdgpu_connector_destroy,
  1316. .force = amdgpu_connector_dvi_force,
  1317. };
  1318. void
  1319. amdgpu_connector_add(struct amdgpu_device *adev,
  1320. uint32_t connector_id,
  1321. uint32_t supported_device,
  1322. int connector_type,
  1323. struct amdgpu_i2c_bus_rec *i2c_bus,
  1324. uint16_t connector_object_id,
  1325. struct amdgpu_hpd *hpd,
  1326. struct amdgpu_router *router)
  1327. {
  1328. struct drm_device *dev = adev->ddev;
  1329. struct drm_connector *connector;
  1330. struct amdgpu_connector *amdgpu_connector;
  1331. struct amdgpu_connector_atom_dig *amdgpu_dig_connector;
  1332. struct drm_encoder *encoder;
  1333. struct amdgpu_encoder *amdgpu_encoder;
  1334. uint32_t subpixel_order = SubPixelNone;
  1335. bool shared_ddc = false;
  1336. bool is_dp_bridge = false;
  1337. bool has_aux = false;
  1338. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  1339. return;
  1340. /* see if we already added it */
  1341. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1342. amdgpu_connector = to_amdgpu_connector(connector);
  1343. if (amdgpu_connector->connector_id == connector_id) {
  1344. amdgpu_connector->devices |= supported_device;
  1345. return;
  1346. }
  1347. if (amdgpu_connector->ddc_bus && i2c_bus->valid) {
  1348. if (amdgpu_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
  1349. amdgpu_connector->shared_ddc = true;
  1350. shared_ddc = true;
  1351. }
  1352. if (amdgpu_connector->router_bus && router->ddc_valid &&
  1353. (amdgpu_connector->router.router_id == router->router_id)) {
  1354. amdgpu_connector->shared_ddc = false;
  1355. shared_ddc = false;
  1356. }
  1357. }
  1358. }
  1359. /* check if it's a dp bridge */
  1360. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1361. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1362. if (amdgpu_encoder->devices & supported_device) {
  1363. switch (amdgpu_encoder->encoder_id) {
  1364. case ENCODER_OBJECT_ID_TRAVIS:
  1365. case ENCODER_OBJECT_ID_NUTMEG:
  1366. is_dp_bridge = true;
  1367. break;
  1368. default:
  1369. break;
  1370. }
  1371. }
  1372. }
  1373. amdgpu_connector = kzalloc(sizeof(struct amdgpu_connector), GFP_KERNEL);
  1374. if (!amdgpu_connector)
  1375. return;
  1376. connector = &amdgpu_connector->base;
  1377. amdgpu_connector->connector_id = connector_id;
  1378. amdgpu_connector->devices = supported_device;
  1379. amdgpu_connector->shared_ddc = shared_ddc;
  1380. amdgpu_connector->connector_object_id = connector_object_id;
  1381. amdgpu_connector->hpd = *hpd;
  1382. amdgpu_connector->router = *router;
  1383. if (router->ddc_valid || router->cd_valid) {
  1384. amdgpu_connector->router_bus = amdgpu_i2c_lookup(adev, &router->i2c_info);
  1385. if (!amdgpu_connector->router_bus)
  1386. DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
  1387. }
  1388. if (is_dp_bridge) {
  1389. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1390. if (!amdgpu_dig_connector)
  1391. goto failed;
  1392. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1393. if (i2c_bus->valid) {
  1394. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1395. if (amdgpu_connector->ddc_bus)
  1396. has_aux = true;
  1397. else
  1398. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1399. }
  1400. switch (connector_type) {
  1401. case DRM_MODE_CONNECTOR_VGA:
  1402. case DRM_MODE_CONNECTOR_DVIA:
  1403. default:
  1404. drm_connector_init(dev, &amdgpu_connector->base,
  1405. &amdgpu_connector_dp_funcs, connector_type);
  1406. drm_connector_helper_add(&amdgpu_connector->base,
  1407. &amdgpu_connector_dp_helper_funcs);
  1408. connector->interlace_allowed = true;
  1409. connector->doublescan_allowed = true;
  1410. amdgpu_connector->dac_load_detect = true;
  1411. drm_object_attach_property(&amdgpu_connector->base.base,
  1412. adev->mode_info.load_detect_property,
  1413. 1);
  1414. drm_object_attach_property(&amdgpu_connector->base.base,
  1415. dev->mode_config.scaling_mode_property,
  1416. DRM_MODE_SCALE_NONE);
  1417. break;
  1418. case DRM_MODE_CONNECTOR_DVII:
  1419. case DRM_MODE_CONNECTOR_DVID:
  1420. case DRM_MODE_CONNECTOR_HDMIA:
  1421. case DRM_MODE_CONNECTOR_HDMIB:
  1422. case DRM_MODE_CONNECTOR_DisplayPort:
  1423. drm_connector_init(dev, &amdgpu_connector->base,
  1424. &amdgpu_connector_dp_funcs, connector_type);
  1425. drm_connector_helper_add(&amdgpu_connector->base,
  1426. &amdgpu_connector_dp_helper_funcs);
  1427. drm_object_attach_property(&amdgpu_connector->base.base,
  1428. adev->mode_info.underscan_property,
  1429. UNDERSCAN_OFF);
  1430. drm_object_attach_property(&amdgpu_connector->base.base,
  1431. adev->mode_info.underscan_hborder_property,
  1432. 0);
  1433. drm_object_attach_property(&amdgpu_connector->base.base,
  1434. adev->mode_info.underscan_vborder_property,
  1435. 0);
  1436. drm_object_attach_property(&amdgpu_connector->base.base,
  1437. dev->mode_config.scaling_mode_property,
  1438. DRM_MODE_SCALE_NONE);
  1439. drm_object_attach_property(&amdgpu_connector->base.base,
  1440. adev->mode_info.dither_property,
  1441. AMDGPU_FMT_DITHER_DISABLE);
  1442. if (amdgpu_audio != 0)
  1443. drm_object_attach_property(&amdgpu_connector->base.base,
  1444. adev->mode_info.audio_property,
  1445. AMDGPU_AUDIO_AUTO);
  1446. subpixel_order = SubPixelHorizontalRGB;
  1447. connector->interlace_allowed = true;
  1448. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1449. connector->doublescan_allowed = true;
  1450. else
  1451. connector->doublescan_allowed = false;
  1452. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1453. amdgpu_connector->dac_load_detect = true;
  1454. drm_object_attach_property(&amdgpu_connector->base.base,
  1455. adev->mode_info.load_detect_property,
  1456. 1);
  1457. }
  1458. break;
  1459. case DRM_MODE_CONNECTOR_LVDS:
  1460. case DRM_MODE_CONNECTOR_eDP:
  1461. drm_connector_init(dev, &amdgpu_connector->base,
  1462. &amdgpu_connector_edp_funcs, connector_type);
  1463. drm_connector_helper_add(&amdgpu_connector->base,
  1464. &amdgpu_connector_dp_helper_funcs);
  1465. drm_object_attach_property(&amdgpu_connector->base.base,
  1466. dev->mode_config.scaling_mode_property,
  1467. DRM_MODE_SCALE_FULLSCREEN);
  1468. subpixel_order = SubPixelHorizontalRGB;
  1469. connector->interlace_allowed = false;
  1470. connector->doublescan_allowed = false;
  1471. break;
  1472. }
  1473. } else {
  1474. switch (connector_type) {
  1475. case DRM_MODE_CONNECTOR_VGA:
  1476. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_vga_funcs, connector_type);
  1477. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_vga_helper_funcs);
  1478. if (i2c_bus->valid) {
  1479. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1480. if (!amdgpu_connector->ddc_bus)
  1481. DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1482. }
  1483. amdgpu_connector->dac_load_detect = true;
  1484. drm_object_attach_property(&amdgpu_connector->base.base,
  1485. adev->mode_info.load_detect_property,
  1486. 1);
  1487. drm_object_attach_property(&amdgpu_connector->base.base,
  1488. dev->mode_config.scaling_mode_property,
  1489. DRM_MODE_SCALE_NONE);
  1490. /* no HPD on analog connectors */
  1491. amdgpu_connector->hpd.hpd = AMDGPU_HPD_NONE;
  1492. connector->interlace_allowed = true;
  1493. connector->doublescan_allowed = true;
  1494. break;
  1495. case DRM_MODE_CONNECTOR_DVIA:
  1496. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_vga_funcs, connector_type);
  1497. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_vga_helper_funcs);
  1498. if (i2c_bus->valid) {
  1499. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1500. if (!amdgpu_connector->ddc_bus)
  1501. DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1502. }
  1503. amdgpu_connector->dac_load_detect = true;
  1504. drm_object_attach_property(&amdgpu_connector->base.base,
  1505. adev->mode_info.load_detect_property,
  1506. 1);
  1507. drm_object_attach_property(&amdgpu_connector->base.base,
  1508. dev->mode_config.scaling_mode_property,
  1509. DRM_MODE_SCALE_NONE);
  1510. /* no HPD on analog connectors */
  1511. amdgpu_connector->hpd.hpd = AMDGPU_HPD_NONE;
  1512. connector->interlace_allowed = true;
  1513. connector->doublescan_allowed = true;
  1514. break;
  1515. case DRM_MODE_CONNECTOR_DVII:
  1516. case DRM_MODE_CONNECTOR_DVID:
  1517. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1518. if (!amdgpu_dig_connector)
  1519. goto failed;
  1520. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1521. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dvi_funcs, connector_type);
  1522. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dvi_helper_funcs);
  1523. if (i2c_bus->valid) {
  1524. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1525. if (!amdgpu_connector->ddc_bus)
  1526. DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1527. }
  1528. subpixel_order = SubPixelHorizontalRGB;
  1529. drm_object_attach_property(&amdgpu_connector->base.base,
  1530. adev->mode_info.coherent_mode_property,
  1531. 1);
  1532. drm_object_attach_property(&amdgpu_connector->base.base,
  1533. adev->mode_info.underscan_property,
  1534. UNDERSCAN_OFF);
  1535. drm_object_attach_property(&amdgpu_connector->base.base,
  1536. adev->mode_info.underscan_hborder_property,
  1537. 0);
  1538. drm_object_attach_property(&amdgpu_connector->base.base,
  1539. adev->mode_info.underscan_vborder_property,
  1540. 0);
  1541. drm_object_attach_property(&amdgpu_connector->base.base,
  1542. dev->mode_config.scaling_mode_property,
  1543. DRM_MODE_SCALE_NONE);
  1544. if (amdgpu_audio != 0) {
  1545. drm_object_attach_property(&amdgpu_connector->base.base,
  1546. adev->mode_info.audio_property,
  1547. AMDGPU_AUDIO_AUTO);
  1548. }
  1549. drm_object_attach_property(&amdgpu_connector->base.base,
  1550. adev->mode_info.dither_property,
  1551. AMDGPU_FMT_DITHER_DISABLE);
  1552. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1553. amdgpu_connector->dac_load_detect = true;
  1554. drm_object_attach_property(&amdgpu_connector->base.base,
  1555. adev->mode_info.load_detect_property,
  1556. 1);
  1557. }
  1558. connector->interlace_allowed = true;
  1559. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  1560. connector->doublescan_allowed = true;
  1561. else
  1562. connector->doublescan_allowed = false;
  1563. break;
  1564. case DRM_MODE_CONNECTOR_HDMIA:
  1565. case DRM_MODE_CONNECTOR_HDMIB:
  1566. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1567. if (!amdgpu_dig_connector)
  1568. goto failed;
  1569. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1570. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dvi_funcs, connector_type);
  1571. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dvi_helper_funcs);
  1572. if (i2c_bus->valid) {
  1573. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1574. if (!amdgpu_connector->ddc_bus)
  1575. DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1576. }
  1577. drm_object_attach_property(&amdgpu_connector->base.base,
  1578. adev->mode_info.coherent_mode_property,
  1579. 1);
  1580. drm_object_attach_property(&amdgpu_connector->base.base,
  1581. adev->mode_info.underscan_property,
  1582. UNDERSCAN_OFF);
  1583. drm_object_attach_property(&amdgpu_connector->base.base,
  1584. adev->mode_info.underscan_hborder_property,
  1585. 0);
  1586. drm_object_attach_property(&amdgpu_connector->base.base,
  1587. adev->mode_info.underscan_vborder_property,
  1588. 0);
  1589. drm_object_attach_property(&amdgpu_connector->base.base,
  1590. dev->mode_config.scaling_mode_property,
  1591. DRM_MODE_SCALE_NONE);
  1592. if (amdgpu_audio != 0) {
  1593. drm_object_attach_property(&amdgpu_connector->base.base,
  1594. adev->mode_info.audio_property,
  1595. AMDGPU_AUDIO_AUTO);
  1596. }
  1597. drm_object_attach_property(&amdgpu_connector->base.base,
  1598. adev->mode_info.dither_property,
  1599. AMDGPU_FMT_DITHER_DISABLE);
  1600. subpixel_order = SubPixelHorizontalRGB;
  1601. connector->interlace_allowed = true;
  1602. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1603. connector->doublescan_allowed = true;
  1604. else
  1605. connector->doublescan_allowed = false;
  1606. break;
  1607. case DRM_MODE_CONNECTOR_DisplayPort:
  1608. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1609. if (!amdgpu_dig_connector)
  1610. goto failed;
  1611. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1612. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dp_funcs, connector_type);
  1613. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dp_helper_funcs);
  1614. if (i2c_bus->valid) {
  1615. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1616. if (amdgpu_connector->ddc_bus)
  1617. has_aux = true;
  1618. else
  1619. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1620. }
  1621. subpixel_order = SubPixelHorizontalRGB;
  1622. drm_object_attach_property(&amdgpu_connector->base.base,
  1623. adev->mode_info.coherent_mode_property,
  1624. 1);
  1625. drm_object_attach_property(&amdgpu_connector->base.base,
  1626. adev->mode_info.underscan_property,
  1627. UNDERSCAN_OFF);
  1628. drm_object_attach_property(&amdgpu_connector->base.base,
  1629. adev->mode_info.underscan_hborder_property,
  1630. 0);
  1631. drm_object_attach_property(&amdgpu_connector->base.base,
  1632. adev->mode_info.underscan_vborder_property,
  1633. 0);
  1634. drm_object_attach_property(&amdgpu_connector->base.base,
  1635. dev->mode_config.scaling_mode_property,
  1636. DRM_MODE_SCALE_NONE);
  1637. if (amdgpu_audio != 0) {
  1638. drm_object_attach_property(&amdgpu_connector->base.base,
  1639. adev->mode_info.audio_property,
  1640. AMDGPU_AUDIO_AUTO);
  1641. }
  1642. drm_object_attach_property(&amdgpu_connector->base.base,
  1643. adev->mode_info.dither_property,
  1644. AMDGPU_FMT_DITHER_DISABLE);
  1645. connector->interlace_allowed = true;
  1646. /* in theory with a DP to VGA converter... */
  1647. connector->doublescan_allowed = false;
  1648. break;
  1649. case DRM_MODE_CONNECTOR_eDP:
  1650. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1651. if (!amdgpu_dig_connector)
  1652. goto failed;
  1653. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1654. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_edp_funcs, connector_type);
  1655. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dp_helper_funcs);
  1656. if (i2c_bus->valid) {
  1657. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1658. if (amdgpu_connector->ddc_bus)
  1659. has_aux = true;
  1660. else
  1661. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1662. }
  1663. drm_object_attach_property(&amdgpu_connector->base.base,
  1664. dev->mode_config.scaling_mode_property,
  1665. DRM_MODE_SCALE_FULLSCREEN);
  1666. subpixel_order = SubPixelHorizontalRGB;
  1667. connector->interlace_allowed = false;
  1668. connector->doublescan_allowed = false;
  1669. break;
  1670. case DRM_MODE_CONNECTOR_LVDS:
  1671. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1672. if (!amdgpu_dig_connector)
  1673. goto failed;
  1674. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1675. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_lvds_funcs, connector_type);
  1676. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_lvds_helper_funcs);
  1677. if (i2c_bus->valid) {
  1678. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1679. if (!amdgpu_connector->ddc_bus)
  1680. DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1681. }
  1682. drm_object_attach_property(&amdgpu_connector->base.base,
  1683. dev->mode_config.scaling_mode_property,
  1684. DRM_MODE_SCALE_FULLSCREEN);
  1685. subpixel_order = SubPixelHorizontalRGB;
  1686. connector->interlace_allowed = false;
  1687. connector->doublescan_allowed = false;
  1688. break;
  1689. }
  1690. }
  1691. if (amdgpu_connector->hpd.hpd == AMDGPU_HPD_NONE) {
  1692. if (i2c_bus->valid) {
  1693. connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  1694. DRM_CONNECTOR_POLL_DISCONNECT;
  1695. }
  1696. } else
  1697. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1698. connector->display_info.subpixel_order = subpixel_order;
  1699. drm_connector_register(connector);
  1700. if (has_aux)
  1701. amdgpu_atombios_dp_aux_init(amdgpu_connector);
  1702. return;
  1703. failed:
  1704. drm_connector_cleanup(connector);
  1705. kfree(connector);
  1706. }