amdgpu_connectors.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  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->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->max_tmds_clock * 1000;
  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,
  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,
  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, 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. 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. return connector_status_disconnected;
  631. }
  632. if (encoder) {
  633. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  634. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  635. /* check if panel is valid */
  636. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  637. ret = connector_status_connected;
  638. }
  639. /* check for edid as well */
  640. amdgpu_connector_get_edid(connector);
  641. if (amdgpu_connector->edid)
  642. ret = connector_status_connected;
  643. /* check acpi lid status ??? */
  644. amdgpu_connector_update_scratch_regs(connector, ret);
  645. if (!drm_kms_helper_is_poll_worker()) {
  646. pm_runtime_mark_last_busy(connector->dev->dev);
  647. pm_runtime_put_autosuspend(connector->dev->dev);
  648. }
  649. return ret;
  650. }
  651. static void amdgpu_connector_destroy(struct drm_connector *connector)
  652. {
  653. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  654. if (amdgpu_connector->ddc_bus->has_aux)
  655. drm_dp_aux_unregister(&amdgpu_connector->ddc_bus->aux);
  656. amdgpu_connector_free_edid(connector);
  657. kfree(amdgpu_connector->con_priv);
  658. drm_connector_unregister(connector);
  659. drm_connector_cleanup(connector);
  660. kfree(connector);
  661. }
  662. static int amdgpu_connector_set_lcd_property(struct drm_connector *connector,
  663. struct drm_property *property,
  664. uint64_t value)
  665. {
  666. struct drm_device *dev = connector->dev;
  667. struct amdgpu_encoder *amdgpu_encoder;
  668. enum amdgpu_rmx_type rmx_type;
  669. DRM_DEBUG_KMS("\n");
  670. if (property != dev->mode_config.scaling_mode_property)
  671. return 0;
  672. if (connector->encoder)
  673. amdgpu_encoder = to_amdgpu_encoder(connector->encoder);
  674. else {
  675. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  676. amdgpu_encoder = to_amdgpu_encoder(connector_funcs->best_encoder(connector));
  677. }
  678. switch (value) {
  679. case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
  680. case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
  681. case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
  682. default:
  683. case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
  684. }
  685. if (amdgpu_encoder->rmx_type == rmx_type)
  686. return 0;
  687. amdgpu_encoder->rmx_type = rmx_type;
  688. amdgpu_connector_property_change_mode(&amdgpu_encoder->base);
  689. return 0;
  690. }
  691. static const struct drm_connector_helper_funcs amdgpu_connector_lvds_helper_funcs = {
  692. .get_modes = amdgpu_connector_lvds_get_modes,
  693. .mode_valid = amdgpu_connector_lvds_mode_valid,
  694. .best_encoder = amdgpu_connector_best_single_encoder,
  695. };
  696. static const struct drm_connector_funcs amdgpu_connector_lvds_funcs = {
  697. .dpms = drm_helper_connector_dpms,
  698. .detect = amdgpu_connector_lvds_detect,
  699. .fill_modes = drm_helper_probe_single_connector_modes,
  700. .destroy = amdgpu_connector_destroy,
  701. .set_property = amdgpu_connector_set_lcd_property,
  702. };
  703. static int amdgpu_connector_vga_get_modes(struct drm_connector *connector)
  704. {
  705. int ret;
  706. amdgpu_connector_get_edid(connector);
  707. ret = amdgpu_connector_ddc_get_modes(connector);
  708. return ret;
  709. }
  710. static int amdgpu_connector_vga_mode_valid(struct drm_connector *connector,
  711. struct drm_display_mode *mode)
  712. {
  713. struct drm_device *dev = connector->dev;
  714. struct amdgpu_device *adev = dev->dev_private;
  715. /* XXX check mode bandwidth */
  716. if ((mode->clock / 10) > adev->clock.max_pixel_clock)
  717. return MODE_CLOCK_HIGH;
  718. return MODE_OK;
  719. }
  720. static enum drm_connector_status
  721. amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
  722. {
  723. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  724. struct drm_encoder *encoder;
  725. const struct drm_encoder_helper_funcs *encoder_funcs;
  726. bool dret = false;
  727. enum drm_connector_status ret = connector_status_disconnected;
  728. int r;
  729. if (!drm_kms_helper_is_poll_worker()) {
  730. r = pm_runtime_get_sync(connector->dev->dev);
  731. if (r < 0)
  732. return connector_status_disconnected;
  733. }
  734. encoder = amdgpu_connector_best_single_encoder(connector);
  735. if (!encoder)
  736. ret = connector_status_disconnected;
  737. if (amdgpu_connector->ddc_bus)
  738. dret = amdgpu_ddc_probe(amdgpu_connector, false);
  739. if (dret) {
  740. amdgpu_connector->detected_by_load = false;
  741. amdgpu_connector_free_edid(connector);
  742. amdgpu_connector_get_edid(connector);
  743. if (!amdgpu_connector->edid) {
  744. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  745. connector->name);
  746. ret = connector_status_connected;
  747. } else {
  748. amdgpu_connector->use_digital =
  749. !!(amdgpu_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  750. /* some oems have boards with separate digital and analog connectors
  751. * with a shared ddc line (often vga + hdmi)
  752. */
  753. if (amdgpu_connector->use_digital && amdgpu_connector->shared_ddc) {
  754. amdgpu_connector_free_edid(connector);
  755. ret = connector_status_disconnected;
  756. } else {
  757. ret = connector_status_connected;
  758. }
  759. }
  760. } else {
  761. /* if we aren't forcing don't do destructive polling */
  762. if (!force) {
  763. /* only return the previous status if we last
  764. * detected a monitor via load.
  765. */
  766. if (amdgpu_connector->detected_by_load)
  767. ret = connector->status;
  768. goto out;
  769. }
  770. if (amdgpu_connector->dac_load_detect && encoder) {
  771. encoder_funcs = encoder->helper_private;
  772. ret = encoder_funcs->detect(encoder, connector);
  773. if (ret != connector_status_disconnected)
  774. amdgpu_connector->detected_by_load = true;
  775. }
  776. }
  777. amdgpu_connector_update_scratch_regs(connector, ret);
  778. out:
  779. if (!drm_kms_helper_is_poll_worker()) {
  780. pm_runtime_mark_last_busy(connector->dev->dev);
  781. pm_runtime_put_autosuspend(connector->dev->dev);
  782. }
  783. return ret;
  784. }
  785. static const struct drm_connector_helper_funcs amdgpu_connector_vga_helper_funcs = {
  786. .get_modes = amdgpu_connector_vga_get_modes,
  787. .mode_valid = amdgpu_connector_vga_mode_valid,
  788. .best_encoder = amdgpu_connector_best_single_encoder,
  789. };
  790. static const struct drm_connector_funcs amdgpu_connector_vga_funcs = {
  791. .dpms = drm_helper_connector_dpms,
  792. .detect = amdgpu_connector_vga_detect,
  793. .fill_modes = drm_helper_probe_single_connector_modes,
  794. .destroy = amdgpu_connector_destroy,
  795. .set_property = amdgpu_connector_set_property,
  796. };
  797. static bool
  798. amdgpu_connector_check_hpd_status_unchanged(struct drm_connector *connector)
  799. {
  800. struct drm_device *dev = connector->dev;
  801. struct amdgpu_device *adev = dev->dev_private;
  802. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  803. enum drm_connector_status status;
  804. if (amdgpu_connector->hpd.hpd != AMDGPU_HPD_NONE) {
  805. if (amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd))
  806. status = connector_status_connected;
  807. else
  808. status = connector_status_disconnected;
  809. if (connector->status == status)
  810. return true;
  811. }
  812. return false;
  813. }
  814. /*
  815. * DVI is complicated
  816. * Do a DDC probe, if DDC probe passes, get the full EDID so
  817. * we can do analog/digital monitor detection at this point.
  818. * If the monitor is an analog monitor or we got no DDC,
  819. * we need to find the DAC encoder object for this connector.
  820. * If we got no DDC, we do load detection on the DAC encoder object.
  821. * If we got analog DDC or load detection passes on the DAC encoder
  822. * we have to check if this analog encoder is shared with anyone else (TV)
  823. * if its shared we have to set the other connector to disconnected.
  824. */
  825. static enum drm_connector_status
  826. amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)
  827. {
  828. struct drm_device *dev = connector->dev;
  829. struct amdgpu_device *adev = dev->dev_private;
  830. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  831. struct drm_encoder *encoder = NULL;
  832. const struct drm_encoder_helper_funcs *encoder_funcs;
  833. int i, r;
  834. enum drm_connector_status ret = connector_status_disconnected;
  835. bool dret = false, broken_edid = false;
  836. if (!drm_kms_helper_is_poll_worker()) {
  837. r = pm_runtime_get_sync(connector->dev->dev);
  838. if (r < 0)
  839. return connector_status_disconnected;
  840. }
  841. if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
  842. ret = connector->status;
  843. goto exit;
  844. }
  845. if (amdgpu_connector->ddc_bus)
  846. dret = amdgpu_ddc_probe(amdgpu_connector, false);
  847. if (dret) {
  848. amdgpu_connector->detected_by_load = false;
  849. amdgpu_connector_free_edid(connector);
  850. amdgpu_connector_get_edid(connector);
  851. if (!amdgpu_connector->edid) {
  852. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  853. connector->name);
  854. ret = connector_status_connected;
  855. broken_edid = true; /* defer use_digital to later */
  856. } else {
  857. amdgpu_connector->use_digital =
  858. !!(amdgpu_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  859. /* some oems have boards with separate digital and analog connectors
  860. * with a shared ddc line (often vga + hdmi)
  861. */
  862. if ((!amdgpu_connector->use_digital) && amdgpu_connector->shared_ddc) {
  863. amdgpu_connector_free_edid(connector);
  864. ret = connector_status_disconnected;
  865. } else {
  866. ret = connector_status_connected;
  867. }
  868. /* This gets complicated. We have boards with VGA + HDMI with a
  869. * shared DDC line and we have boards with DVI-D + HDMI with a shared
  870. * DDC line. The latter is more complex because with DVI<->HDMI adapters
  871. * you don't really know what's connected to which port as both are digital.
  872. */
  873. if (amdgpu_connector->shared_ddc && (ret == connector_status_connected)) {
  874. struct drm_connector *list_connector;
  875. struct amdgpu_connector *list_amdgpu_connector;
  876. list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
  877. if (connector == list_connector)
  878. continue;
  879. list_amdgpu_connector = to_amdgpu_connector(list_connector);
  880. if (list_amdgpu_connector->shared_ddc &&
  881. (list_amdgpu_connector->ddc_bus->rec.i2c_id ==
  882. amdgpu_connector->ddc_bus->rec.i2c_id)) {
  883. /* cases where both connectors are digital */
  884. if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
  885. /* hpd is our only option in this case */
  886. if (!amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd)) {
  887. amdgpu_connector_free_edid(connector);
  888. ret = connector_status_disconnected;
  889. }
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. if ((ret == connector_status_connected) && (amdgpu_connector->use_digital == true))
  897. goto out;
  898. /* DVI-D and HDMI-A are digital only */
  899. if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
  900. (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
  901. goto out;
  902. /* if we aren't forcing don't do destructive polling */
  903. if (!force) {
  904. /* only return the previous status if we last
  905. * detected a monitor via load.
  906. */
  907. if (amdgpu_connector->detected_by_load)
  908. ret = connector->status;
  909. goto out;
  910. }
  911. /* find analog encoder */
  912. if (amdgpu_connector->dac_load_detect) {
  913. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  914. if (connector->encoder_ids[i] == 0)
  915. break;
  916. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  917. if (!encoder)
  918. continue;
  919. if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
  920. encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
  921. continue;
  922. encoder_funcs = encoder->helper_private;
  923. if (encoder_funcs->detect) {
  924. if (!broken_edid) {
  925. if (ret != connector_status_connected) {
  926. /* deal with analog monitors without DDC */
  927. ret = encoder_funcs->detect(encoder, connector);
  928. if (ret == connector_status_connected) {
  929. amdgpu_connector->use_digital = false;
  930. }
  931. if (ret != connector_status_disconnected)
  932. amdgpu_connector->detected_by_load = true;
  933. }
  934. } else {
  935. enum drm_connector_status lret;
  936. /* assume digital unless load detected otherwise */
  937. amdgpu_connector->use_digital = true;
  938. lret = encoder_funcs->detect(encoder, connector);
  939. DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
  940. if (lret == connector_status_connected)
  941. amdgpu_connector->use_digital = false;
  942. }
  943. break;
  944. }
  945. }
  946. }
  947. out:
  948. /* updated in get modes as well since we need to know if it's analog or digital */
  949. amdgpu_connector_update_scratch_regs(connector, ret);
  950. exit:
  951. if (!drm_kms_helper_is_poll_worker()) {
  952. pm_runtime_mark_last_busy(connector->dev->dev);
  953. pm_runtime_put_autosuspend(connector->dev->dev);
  954. }
  955. return ret;
  956. }
  957. /* okay need to be smart in here about which encoder to pick */
  958. static struct drm_encoder *
  959. amdgpu_connector_dvi_encoder(struct drm_connector *connector)
  960. {
  961. int enc_id = connector->encoder_ids[0];
  962. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  963. struct drm_encoder *encoder;
  964. int i;
  965. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  966. if (connector->encoder_ids[i] == 0)
  967. break;
  968. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  969. if (!encoder)
  970. continue;
  971. if (amdgpu_connector->use_digital == true) {
  972. if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
  973. return encoder;
  974. } else {
  975. if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
  976. encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
  977. return encoder;
  978. }
  979. }
  980. /* see if we have a default encoder TODO */
  981. /* then check use digitial */
  982. /* pick the first one */
  983. if (enc_id)
  984. return drm_encoder_find(connector->dev, enc_id);
  985. return NULL;
  986. }
  987. static void amdgpu_connector_dvi_force(struct drm_connector *connector)
  988. {
  989. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  990. if (connector->force == DRM_FORCE_ON)
  991. amdgpu_connector->use_digital = false;
  992. if (connector->force == DRM_FORCE_ON_DIGITAL)
  993. amdgpu_connector->use_digital = true;
  994. }
  995. static int amdgpu_connector_dvi_mode_valid(struct drm_connector *connector,
  996. struct drm_display_mode *mode)
  997. {
  998. struct drm_device *dev = connector->dev;
  999. struct amdgpu_device *adev = dev->dev_private;
  1000. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1001. /* XXX check mode bandwidth */
  1002. if (amdgpu_connector->use_digital && (mode->clock > 165000)) {
  1003. if ((amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
  1004. (amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
  1005. (amdgpu_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B)) {
  1006. return MODE_OK;
  1007. } else if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  1008. /* HDMI 1.3+ supports max clock of 340 Mhz */
  1009. if (mode->clock > 340000)
  1010. return MODE_CLOCK_HIGH;
  1011. else
  1012. return MODE_OK;
  1013. } else {
  1014. return MODE_CLOCK_HIGH;
  1015. }
  1016. }
  1017. /* check against the max pixel clock */
  1018. if ((mode->clock / 10) > adev->clock.max_pixel_clock)
  1019. return MODE_CLOCK_HIGH;
  1020. return MODE_OK;
  1021. }
  1022. static const struct drm_connector_helper_funcs amdgpu_connector_dvi_helper_funcs = {
  1023. .get_modes = amdgpu_connector_vga_get_modes,
  1024. .mode_valid = amdgpu_connector_dvi_mode_valid,
  1025. .best_encoder = amdgpu_connector_dvi_encoder,
  1026. };
  1027. static const struct drm_connector_funcs amdgpu_connector_dvi_funcs = {
  1028. .dpms = drm_helper_connector_dpms,
  1029. .detect = amdgpu_connector_dvi_detect,
  1030. .fill_modes = drm_helper_probe_single_connector_modes,
  1031. .set_property = amdgpu_connector_set_property,
  1032. .destroy = amdgpu_connector_destroy,
  1033. .force = amdgpu_connector_dvi_force,
  1034. };
  1035. static int amdgpu_connector_dp_get_modes(struct drm_connector *connector)
  1036. {
  1037. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1038. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1039. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1040. int ret;
  1041. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1042. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1043. struct drm_display_mode *mode;
  1044. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
  1045. if (!amdgpu_dig_connector->edp_on)
  1046. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1047. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1048. amdgpu_connector_get_edid(connector);
  1049. ret = amdgpu_connector_ddc_get_modes(connector);
  1050. if (!amdgpu_dig_connector->edp_on)
  1051. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1052. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1053. } else {
  1054. /* need to setup ddc on the bridge */
  1055. if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1056. ENCODER_OBJECT_ID_NONE) {
  1057. if (encoder)
  1058. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1059. }
  1060. amdgpu_connector_get_edid(connector);
  1061. ret = amdgpu_connector_ddc_get_modes(connector);
  1062. }
  1063. if (ret > 0) {
  1064. if (encoder) {
  1065. amdgpu_connector_fixup_lcd_native_mode(encoder, connector);
  1066. /* add scaled modes */
  1067. amdgpu_connector_add_common_modes(encoder, connector);
  1068. }
  1069. return ret;
  1070. }
  1071. if (!encoder)
  1072. return 0;
  1073. /* we have no EDID modes */
  1074. mode = amdgpu_connector_lcd_native_mode(encoder);
  1075. if (mode) {
  1076. ret = 1;
  1077. drm_mode_probed_add(connector, mode);
  1078. /* add the width/height from vbios tables if available */
  1079. connector->display_info.width_mm = mode->width_mm;
  1080. connector->display_info.height_mm = mode->height_mm;
  1081. /* add scaled modes */
  1082. amdgpu_connector_add_common_modes(encoder, connector);
  1083. }
  1084. } else {
  1085. /* need to setup ddc on the bridge */
  1086. if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1087. ENCODER_OBJECT_ID_NONE) {
  1088. if (encoder)
  1089. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1090. }
  1091. amdgpu_connector_get_edid(connector);
  1092. ret = amdgpu_connector_ddc_get_modes(connector);
  1093. amdgpu_get_native_mode(connector);
  1094. }
  1095. return ret;
  1096. }
  1097. u16 amdgpu_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
  1098. {
  1099. struct drm_encoder *encoder;
  1100. struct amdgpu_encoder *amdgpu_encoder;
  1101. int i;
  1102. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1103. if (connector->encoder_ids[i] == 0)
  1104. break;
  1105. encoder = drm_encoder_find(connector->dev,
  1106. connector->encoder_ids[i]);
  1107. if (!encoder)
  1108. continue;
  1109. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1110. switch (amdgpu_encoder->encoder_id) {
  1111. case ENCODER_OBJECT_ID_TRAVIS:
  1112. case ENCODER_OBJECT_ID_NUTMEG:
  1113. return amdgpu_encoder->encoder_id;
  1114. default:
  1115. break;
  1116. }
  1117. }
  1118. return ENCODER_OBJECT_ID_NONE;
  1119. }
  1120. static bool amdgpu_connector_encoder_is_hbr2(struct drm_connector *connector)
  1121. {
  1122. struct drm_encoder *encoder;
  1123. struct amdgpu_encoder *amdgpu_encoder;
  1124. int i;
  1125. bool found = false;
  1126. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1127. if (connector->encoder_ids[i] == 0)
  1128. break;
  1129. encoder = drm_encoder_find(connector->dev,
  1130. connector->encoder_ids[i]);
  1131. if (!encoder)
  1132. continue;
  1133. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1134. if (amdgpu_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
  1135. found = true;
  1136. }
  1137. return found;
  1138. }
  1139. bool amdgpu_connector_is_dp12_capable(struct drm_connector *connector)
  1140. {
  1141. struct drm_device *dev = connector->dev;
  1142. struct amdgpu_device *adev = dev->dev_private;
  1143. if ((adev->clock.default_dispclk >= 53900) &&
  1144. amdgpu_connector_encoder_is_hbr2(connector)) {
  1145. return true;
  1146. }
  1147. return false;
  1148. }
  1149. static enum drm_connector_status
  1150. amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
  1151. {
  1152. struct drm_device *dev = connector->dev;
  1153. struct amdgpu_device *adev = dev->dev_private;
  1154. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1155. enum drm_connector_status ret = connector_status_disconnected;
  1156. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1157. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1158. int r;
  1159. if (!drm_kms_helper_is_poll_worker()) {
  1160. r = pm_runtime_get_sync(connector->dev->dev);
  1161. if (r < 0)
  1162. return connector_status_disconnected;
  1163. }
  1164. if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
  1165. ret = connector->status;
  1166. goto out;
  1167. }
  1168. amdgpu_connector_free_edid(connector);
  1169. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1170. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1171. if (encoder) {
  1172. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1173. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  1174. /* check if panel is valid */
  1175. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  1176. ret = connector_status_connected;
  1177. }
  1178. /* eDP is always DP */
  1179. amdgpu_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1180. if (!amdgpu_dig_connector->edp_on)
  1181. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1182. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1183. if (!amdgpu_atombios_dp_get_dpcd(amdgpu_connector))
  1184. ret = connector_status_connected;
  1185. if (!amdgpu_dig_connector->edp_on)
  1186. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  1187. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1188. } else if (amdgpu_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1189. ENCODER_OBJECT_ID_NONE) {
  1190. /* DP bridges are always DP */
  1191. amdgpu_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1192. /* get the DPCD from the bridge */
  1193. amdgpu_atombios_dp_get_dpcd(amdgpu_connector);
  1194. if (encoder) {
  1195. /* setup ddc on the bridge */
  1196. amdgpu_atombios_encoder_setup_ext_encoder_ddc(encoder);
  1197. /* bridge chips are always aux */
  1198. if (amdgpu_ddc_probe(amdgpu_connector, true)) /* try DDC */
  1199. ret = connector_status_connected;
  1200. else if (amdgpu_connector->dac_load_detect) { /* try load detection */
  1201. const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1202. ret = encoder_funcs->detect(encoder, connector);
  1203. }
  1204. }
  1205. } else {
  1206. amdgpu_dig_connector->dp_sink_type =
  1207. amdgpu_atombios_dp_get_sinktype(amdgpu_connector);
  1208. if (amdgpu_display_hpd_sense(adev, amdgpu_connector->hpd.hpd)) {
  1209. ret = connector_status_connected;
  1210. if (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
  1211. amdgpu_atombios_dp_get_dpcd(amdgpu_connector);
  1212. } else {
  1213. if (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
  1214. if (!amdgpu_atombios_dp_get_dpcd(amdgpu_connector))
  1215. ret = connector_status_connected;
  1216. } else {
  1217. /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
  1218. if (amdgpu_ddc_probe(amdgpu_connector, false))
  1219. ret = connector_status_connected;
  1220. }
  1221. }
  1222. }
  1223. amdgpu_connector_update_scratch_regs(connector, ret);
  1224. out:
  1225. if (!drm_kms_helper_is_poll_worker()) {
  1226. pm_runtime_mark_last_busy(connector->dev->dev);
  1227. pm_runtime_put_autosuspend(connector->dev->dev);
  1228. }
  1229. return ret;
  1230. }
  1231. static int amdgpu_connector_dp_mode_valid(struct drm_connector *connector,
  1232. struct drm_display_mode *mode)
  1233. {
  1234. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  1235. struct amdgpu_connector_atom_dig *amdgpu_dig_connector = amdgpu_connector->con_priv;
  1236. /* XXX check mode bandwidth */
  1237. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1238. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1239. struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
  1240. if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
  1241. return MODE_PANEL;
  1242. if (encoder) {
  1243. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1244. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  1245. /* AVIVO hardware supports downscaling modes larger than the panel
  1246. * to the panel size, but I'm not sure this is desirable.
  1247. */
  1248. if ((mode->hdisplay > native_mode->hdisplay) ||
  1249. (mode->vdisplay > native_mode->vdisplay))
  1250. return MODE_PANEL;
  1251. /* if scaling is disabled, block non-native modes */
  1252. if (amdgpu_encoder->rmx_type == RMX_OFF) {
  1253. if ((mode->hdisplay != native_mode->hdisplay) ||
  1254. (mode->vdisplay != native_mode->vdisplay))
  1255. return MODE_PANEL;
  1256. }
  1257. }
  1258. return MODE_OK;
  1259. } else {
  1260. if ((amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  1261. (amdgpu_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
  1262. return amdgpu_atombios_dp_mode_valid_helper(connector, mode);
  1263. } else {
  1264. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  1265. /* HDMI 1.3+ supports max clock of 340 Mhz */
  1266. if (mode->clock > 340000)
  1267. return MODE_CLOCK_HIGH;
  1268. } else {
  1269. if (mode->clock > 165000)
  1270. return MODE_CLOCK_HIGH;
  1271. }
  1272. }
  1273. }
  1274. return MODE_OK;
  1275. }
  1276. static const struct drm_connector_helper_funcs amdgpu_connector_dp_helper_funcs = {
  1277. .get_modes = amdgpu_connector_dp_get_modes,
  1278. .mode_valid = amdgpu_connector_dp_mode_valid,
  1279. .best_encoder = amdgpu_connector_dvi_encoder,
  1280. };
  1281. static const struct drm_connector_funcs amdgpu_connector_dp_funcs = {
  1282. .dpms = drm_helper_connector_dpms,
  1283. .detect = amdgpu_connector_dp_detect,
  1284. .fill_modes = drm_helper_probe_single_connector_modes,
  1285. .set_property = amdgpu_connector_set_property,
  1286. .destroy = amdgpu_connector_destroy,
  1287. .force = amdgpu_connector_dvi_force,
  1288. };
  1289. static const struct drm_connector_funcs amdgpu_connector_edp_funcs = {
  1290. .dpms = drm_helper_connector_dpms,
  1291. .detect = amdgpu_connector_dp_detect,
  1292. .fill_modes = drm_helper_probe_single_connector_modes,
  1293. .set_property = amdgpu_connector_set_lcd_property,
  1294. .destroy = amdgpu_connector_destroy,
  1295. .force = amdgpu_connector_dvi_force,
  1296. };
  1297. void
  1298. amdgpu_connector_add(struct amdgpu_device *adev,
  1299. uint32_t connector_id,
  1300. uint32_t supported_device,
  1301. int connector_type,
  1302. struct amdgpu_i2c_bus_rec *i2c_bus,
  1303. uint16_t connector_object_id,
  1304. struct amdgpu_hpd *hpd,
  1305. struct amdgpu_router *router)
  1306. {
  1307. struct drm_device *dev = adev->ddev;
  1308. struct drm_connector *connector;
  1309. struct amdgpu_connector *amdgpu_connector;
  1310. struct amdgpu_connector_atom_dig *amdgpu_dig_connector;
  1311. struct drm_encoder *encoder;
  1312. struct amdgpu_encoder *amdgpu_encoder;
  1313. uint32_t subpixel_order = SubPixelNone;
  1314. bool shared_ddc = false;
  1315. bool is_dp_bridge = false;
  1316. bool has_aux = false;
  1317. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  1318. return;
  1319. /* see if we already added it */
  1320. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1321. amdgpu_connector = to_amdgpu_connector(connector);
  1322. if (amdgpu_connector->connector_id == connector_id) {
  1323. amdgpu_connector->devices |= supported_device;
  1324. return;
  1325. }
  1326. if (amdgpu_connector->ddc_bus && i2c_bus->valid) {
  1327. if (amdgpu_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
  1328. amdgpu_connector->shared_ddc = true;
  1329. shared_ddc = true;
  1330. }
  1331. if (amdgpu_connector->router_bus && router->ddc_valid &&
  1332. (amdgpu_connector->router.router_id == router->router_id)) {
  1333. amdgpu_connector->shared_ddc = false;
  1334. shared_ddc = false;
  1335. }
  1336. }
  1337. }
  1338. /* check if it's a dp bridge */
  1339. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1340. amdgpu_encoder = to_amdgpu_encoder(encoder);
  1341. if (amdgpu_encoder->devices & supported_device) {
  1342. switch (amdgpu_encoder->encoder_id) {
  1343. case ENCODER_OBJECT_ID_TRAVIS:
  1344. case ENCODER_OBJECT_ID_NUTMEG:
  1345. is_dp_bridge = true;
  1346. break;
  1347. default:
  1348. break;
  1349. }
  1350. }
  1351. }
  1352. amdgpu_connector = kzalloc(sizeof(struct amdgpu_connector), GFP_KERNEL);
  1353. if (!amdgpu_connector)
  1354. return;
  1355. connector = &amdgpu_connector->base;
  1356. amdgpu_connector->connector_id = connector_id;
  1357. amdgpu_connector->devices = supported_device;
  1358. amdgpu_connector->shared_ddc = shared_ddc;
  1359. amdgpu_connector->connector_object_id = connector_object_id;
  1360. amdgpu_connector->hpd = *hpd;
  1361. amdgpu_connector->router = *router;
  1362. if (router->ddc_valid || router->cd_valid) {
  1363. amdgpu_connector->router_bus = amdgpu_i2c_lookup(adev, &router->i2c_info);
  1364. if (!amdgpu_connector->router_bus)
  1365. DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
  1366. }
  1367. if (is_dp_bridge) {
  1368. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1369. if (!amdgpu_dig_connector)
  1370. goto failed;
  1371. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1372. if (i2c_bus->valid) {
  1373. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1374. if (amdgpu_connector->ddc_bus)
  1375. has_aux = true;
  1376. else
  1377. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1378. }
  1379. switch (connector_type) {
  1380. case DRM_MODE_CONNECTOR_VGA:
  1381. case DRM_MODE_CONNECTOR_DVIA:
  1382. default:
  1383. drm_connector_init(dev, &amdgpu_connector->base,
  1384. &amdgpu_connector_dp_funcs, connector_type);
  1385. drm_connector_helper_add(&amdgpu_connector->base,
  1386. &amdgpu_connector_dp_helper_funcs);
  1387. connector->interlace_allowed = true;
  1388. connector->doublescan_allowed = true;
  1389. amdgpu_connector->dac_load_detect = true;
  1390. drm_object_attach_property(&amdgpu_connector->base.base,
  1391. adev->mode_info.load_detect_property,
  1392. 1);
  1393. drm_object_attach_property(&amdgpu_connector->base.base,
  1394. dev->mode_config.scaling_mode_property,
  1395. DRM_MODE_SCALE_NONE);
  1396. break;
  1397. case DRM_MODE_CONNECTOR_DVII:
  1398. case DRM_MODE_CONNECTOR_DVID:
  1399. case DRM_MODE_CONNECTOR_HDMIA:
  1400. case DRM_MODE_CONNECTOR_HDMIB:
  1401. case DRM_MODE_CONNECTOR_DisplayPort:
  1402. drm_connector_init(dev, &amdgpu_connector->base,
  1403. &amdgpu_connector_dp_funcs, connector_type);
  1404. drm_connector_helper_add(&amdgpu_connector->base,
  1405. &amdgpu_connector_dp_helper_funcs);
  1406. drm_object_attach_property(&amdgpu_connector->base.base,
  1407. adev->mode_info.underscan_property,
  1408. UNDERSCAN_OFF);
  1409. drm_object_attach_property(&amdgpu_connector->base.base,
  1410. adev->mode_info.underscan_hborder_property,
  1411. 0);
  1412. drm_object_attach_property(&amdgpu_connector->base.base,
  1413. adev->mode_info.underscan_vborder_property,
  1414. 0);
  1415. drm_object_attach_property(&amdgpu_connector->base.base,
  1416. dev->mode_config.scaling_mode_property,
  1417. DRM_MODE_SCALE_NONE);
  1418. drm_object_attach_property(&amdgpu_connector->base.base,
  1419. adev->mode_info.dither_property,
  1420. AMDGPU_FMT_DITHER_DISABLE);
  1421. if (amdgpu_audio != 0)
  1422. drm_object_attach_property(&amdgpu_connector->base.base,
  1423. adev->mode_info.audio_property,
  1424. AMDGPU_AUDIO_AUTO);
  1425. subpixel_order = SubPixelHorizontalRGB;
  1426. connector->interlace_allowed = true;
  1427. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1428. connector->doublescan_allowed = true;
  1429. else
  1430. connector->doublescan_allowed = false;
  1431. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1432. amdgpu_connector->dac_load_detect = true;
  1433. drm_object_attach_property(&amdgpu_connector->base.base,
  1434. adev->mode_info.load_detect_property,
  1435. 1);
  1436. }
  1437. break;
  1438. case DRM_MODE_CONNECTOR_LVDS:
  1439. case DRM_MODE_CONNECTOR_eDP:
  1440. drm_connector_init(dev, &amdgpu_connector->base,
  1441. &amdgpu_connector_edp_funcs, connector_type);
  1442. drm_connector_helper_add(&amdgpu_connector->base,
  1443. &amdgpu_connector_dp_helper_funcs);
  1444. drm_object_attach_property(&amdgpu_connector->base.base,
  1445. dev->mode_config.scaling_mode_property,
  1446. DRM_MODE_SCALE_FULLSCREEN);
  1447. subpixel_order = SubPixelHorizontalRGB;
  1448. connector->interlace_allowed = false;
  1449. connector->doublescan_allowed = false;
  1450. break;
  1451. }
  1452. } else {
  1453. switch (connector_type) {
  1454. case DRM_MODE_CONNECTOR_VGA:
  1455. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_vga_funcs, connector_type);
  1456. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_vga_helper_funcs);
  1457. if (i2c_bus->valid) {
  1458. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1459. if (!amdgpu_connector->ddc_bus)
  1460. DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1461. }
  1462. amdgpu_connector->dac_load_detect = true;
  1463. drm_object_attach_property(&amdgpu_connector->base.base,
  1464. adev->mode_info.load_detect_property,
  1465. 1);
  1466. drm_object_attach_property(&amdgpu_connector->base.base,
  1467. dev->mode_config.scaling_mode_property,
  1468. DRM_MODE_SCALE_NONE);
  1469. /* no HPD on analog connectors */
  1470. amdgpu_connector->hpd.hpd = AMDGPU_HPD_NONE;
  1471. connector->interlace_allowed = true;
  1472. connector->doublescan_allowed = true;
  1473. break;
  1474. case DRM_MODE_CONNECTOR_DVIA:
  1475. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_vga_funcs, connector_type);
  1476. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_vga_helper_funcs);
  1477. if (i2c_bus->valid) {
  1478. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1479. if (!amdgpu_connector->ddc_bus)
  1480. DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1481. }
  1482. amdgpu_connector->dac_load_detect = true;
  1483. drm_object_attach_property(&amdgpu_connector->base.base,
  1484. adev->mode_info.load_detect_property,
  1485. 1);
  1486. drm_object_attach_property(&amdgpu_connector->base.base,
  1487. dev->mode_config.scaling_mode_property,
  1488. DRM_MODE_SCALE_NONE);
  1489. /* no HPD on analog connectors */
  1490. amdgpu_connector->hpd.hpd = AMDGPU_HPD_NONE;
  1491. connector->interlace_allowed = true;
  1492. connector->doublescan_allowed = true;
  1493. break;
  1494. case DRM_MODE_CONNECTOR_DVII:
  1495. case DRM_MODE_CONNECTOR_DVID:
  1496. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1497. if (!amdgpu_dig_connector)
  1498. goto failed;
  1499. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1500. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dvi_funcs, connector_type);
  1501. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dvi_helper_funcs);
  1502. if (i2c_bus->valid) {
  1503. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1504. if (!amdgpu_connector->ddc_bus)
  1505. DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1506. }
  1507. subpixel_order = SubPixelHorizontalRGB;
  1508. drm_object_attach_property(&amdgpu_connector->base.base,
  1509. adev->mode_info.coherent_mode_property,
  1510. 1);
  1511. drm_object_attach_property(&amdgpu_connector->base.base,
  1512. adev->mode_info.underscan_property,
  1513. UNDERSCAN_OFF);
  1514. drm_object_attach_property(&amdgpu_connector->base.base,
  1515. adev->mode_info.underscan_hborder_property,
  1516. 0);
  1517. drm_object_attach_property(&amdgpu_connector->base.base,
  1518. adev->mode_info.underscan_vborder_property,
  1519. 0);
  1520. drm_object_attach_property(&amdgpu_connector->base.base,
  1521. dev->mode_config.scaling_mode_property,
  1522. DRM_MODE_SCALE_NONE);
  1523. if (amdgpu_audio != 0) {
  1524. drm_object_attach_property(&amdgpu_connector->base.base,
  1525. adev->mode_info.audio_property,
  1526. AMDGPU_AUDIO_AUTO);
  1527. }
  1528. drm_object_attach_property(&amdgpu_connector->base.base,
  1529. adev->mode_info.dither_property,
  1530. AMDGPU_FMT_DITHER_DISABLE);
  1531. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1532. amdgpu_connector->dac_load_detect = true;
  1533. drm_object_attach_property(&amdgpu_connector->base.base,
  1534. adev->mode_info.load_detect_property,
  1535. 1);
  1536. }
  1537. connector->interlace_allowed = true;
  1538. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  1539. connector->doublescan_allowed = true;
  1540. else
  1541. connector->doublescan_allowed = false;
  1542. break;
  1543. case DRM_MODE_CONNECTOR_HDMIA:
  1544. case DRM_MODE_CONNECTOR_HDMIB:
  1545. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1546. if (!amdgpu_dig_connector)
  1547. goto failed;
  1548. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1549. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dvi_funcs, connector_type);
  1550. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dvi_helper_funcs);
  1551. if (i2c_bus->valid) {
  1552. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1553. if (!amdgpu_connector->ddc_bus)
  1554. DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1555. }
  1556. drm_object_attach_property(&amdgpu_connector->base.base,
  1557. adev->mode_info.coherent_mode_property,
  1558. 1);
  1559. drm_object_attach_property(&amdgpu_connector->base.base,
  1560. adev->mode_info.underscan_property,
  1561. UNDERSCAN_OFF);
  1562. drm_object_attach_property(&amdgpu_connector->base.base,
  1563. adev->mode_info.underscan_hborder_property,
  1564. 0);
  1565. drm_object_attach_property(&amdgpu_connector->base.base,
  1566. adev->mode_info.underscan_vborder_property,
  1567. 0);
  1568. drm_object_attach_property(&amdgpu_connector->base.base,
  1569. dev->mode_config.scaling_mode_property,
  1570. DRM_MODE_SCALE_NONE);
  1571. if (amdgpu_audio != 0) {
  1572. drm_object_attach_property(&amdgpu_connector->base.base,
  1573. adev->mode_info.audio_property,
  1574. AMDGPU_AUDIO_AUTO);
  1575. }
  1576. drm_object_attach_property(&amdgpu_connector->base.base,
  1577. adev->mode_info.dither_property,
  1578. AMDGPU_FMT_DITHER_DISABLE);
  1579. subpixel_order = SubPixelHorizontalRGB;
  1580. connector->interlace_allowed = true;
  1581. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1582. connector->doublescan_allowed = true;
  1583. else
  1584. connector->doublescan_allowed = false;
  1585. break;
  1586. case DRM_MODE_CONNECTOR_DisplayPort:
  1587. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1588. if (!amdgpu_dig_connector)
  1589. goto failed;
  1590. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1591. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_dp_funcs, connector_type);
  1592. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dp_helper_funcs);
  1593. if (i2c_bus->valid) {
  1594. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1595. if (amdgpu_connector->ddc_bus)
  1596. has_aux = true;
  1597. else
  1598. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1599. }
  1600. subpixel_order = SubPixelHorizontalRGB;
  1601. drm_object_attach_property(&amdgpu_connector->base.base,
  1602. adev->mode_info.coherent_mode_property,
  1603. 1);
  1604. drm_object_attach_property(&amdgpu_connector->base.base,
  1605. adev->mode_info.underscan_property,
  1606. UNDERSCAN_OFF);
  1607. drm_object_attach_property(&amdgpu_connector->base.base,
  1608. adev->mode_info.underscan_hborder_property,
  1609. 0);
  1610. drm_object_attach_property(&amdgpu_connector->base.base,
  1611. adev->mode_info.underscan_vborder_property,
  1612. 0);
  1613. drm_object_attach_property(&amdgpu_connector->base.base,
  1614. dev->mode_config.scaling_mode_property,
  1615. DRM_MODE_SCALE_NONE);
  1616. if (amdgpu_audio != 0) {
  1617. drm_object_attach_property(&amdgpu_connector->base.base,
  1618. adev->mode_info.audio_property,
  1619. AMDGPU_AUDIO_AUTO);
  1620. }
  1621. drm_object_attach_property(&amdgpu_connector->base.base,
  1622. adev->mode_info.dither_property,
  1623. AMDGPU_FMT_DITHER_DISABLE);
  1624. connector->interlace_allowed = true;
  1625. /* in theory with a DP to VGA converter... */
  1626. connector->doublescan_allowed = false;
  1627. break;
  1628. case DRM_MODE_CONNECTOR_eDP:
  1629. amdgpu_dig_connector = kzalloc(sizeof(struct amdgpu_connector_atom_dig), GFP_KERNEL);
  1630. if (!amdgpu_dig_connector)
  1631. goto failed;
  1632. amdgpu_connector->con_priv = amdgpu_dig_connector;
  1633. drm_connector_init(dev, &amdgpu_connector->base, &amdgpu_connector_edp_funcs, connector_type);
  1634. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_dp_helper_funcs);
  1635. if (i2c_bus->valid) {
  1636. amdgpu_connector->ddc_bus = amdgpu_i2c_lookup(adev, i2c_bus);
  1637. if (amdgpu_connector->ddc_bus)
  1638. has_aux = true;
  1639. else
  1640. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1641. }
  1642. drm_object_attach_property(&amdgpu_connector->base.base,
  1643. dev->mode_config.scaling_mode_property,
  1644. DRM_MODE_SCALE_FULLSCREEN);
  1645. subpixel_order = SubPixelHorizontalRGB;
  1646. connector->interlace_allowed = false;
  1647. connector->doublescan_allowed = false;
  1648. break;
  1649. case DRM_MODE_CONNECTOR_LVDS:
  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_lvds_funcs, connector_type);
  1655. drm_connector_helper_add(&amdgpu_connector->base, &amdgpu_connector_lvds_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. DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1660. }
  1661. drm_object_attach_property(&amdgpu_connector->base.base,
  1662. dev->mode_config.scaling_mode_property,
  1663. DRM_MODE_SCALE_FULLSCREEN);
  1664. subpixel_order = SubPixelHorizontalRGB;
  1665. connector->interlace_allowed = false;
  1666. connector->doublescan_allowed = false;
  1667. break;
  1668. }
  1669. }
  1670. if (amdgpu_connector->hpd.hpd == AMDGPU_HPD_NONE) {
  1671. if (i2c_bus->valid) {
  1672. connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  1673. DRM_CONNECTOR_POLL_DISCONNECT;
  1674. }
  1675. } else
  1676. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1677. connector->display_info.subpixel_order = subpixel_order;
  1678. drm_connector_register(connector);
  1679. if (has_aux)
  1680. amdgpu_atombios_dp_aux_init(amdgpu_connector);
  1681. return;
  1682. failed:
  1683. drm_connector_cleanup(connector);
  1684. kfree(connector);
  1685. }