radeon_connectors.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  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/drm_dp_mst_helper.h>
  31. #include <drm/radeon_drm.h>
  32. #include "radeon.h"
  33. #include "radeon_audio.h"
  34. #include "atom.h"
  35. #include <linux/pm_runtime.h>
  36. static int radeon_dp_handle_hpd(struct drm_connector *connector)
  37. {
  38. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  39. int ret;
  40. ret = radeon_dp_mst_check_status(radeon_connector);
  41. if (ret == -EINVAL)
  42. return 1;
  43. return 0;
  44. }
  45. void radeon_connector_hotplug(struct drm_connector *connector)
  46. {
  47. struct drm_device *dev = connector->dev;
  48. struct radeon_device *rdev = dev->dev_private;
  49. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  50. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
  51. struct radeon_connector_atom_dig *dig_connector =
  52. radeon_connector->con_priv;
  53. if (radeon_connector->is_mst_connector)
  54. return;
  55. if (dig_connector->is_mst) {
  56. radeon_dp_handle_hpd(connector);
  57. return;
  58. }
  59. }
  60. /* bail if the connector does not have hpd pin, e.g.,
  61. * VGA, TV, etc.
  62. */
  63. if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
  64. return;
  65. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  66. /* if the connector is already off, don't turn it back on */
  67. /* FIXME: This access isn't protected by any locks. */
  68. if (connector->dpms != DRM_MODE_DPMS_ON)
  69. return;
  70. /* just deal with DP (not eDP) here. */
  71. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
  72. struct radeon_connector_atom_dig *dig_connector =
  73. radeon_connector->con_priv;
  74. /* if existing sink type was not DP no need to retrain */
  75. if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
  76. return;
  77. /* first get sink type as it may be reset after (un)plug */
  78. dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
  79. /* don't do anything if sink is not display port, i.e.,
  80. * passive dp->(dvi|hdmi) adaptor
  81. */
  82. if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT &&
  83. radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) &&
  84. radeon_dp_needs_link_train(radeon_connector)) {
  85. /* Don't start link training before we have the DPCD */
  86. if (!radeon_dp_getdpcd(radeon_connector))
  87. return;
  88. /* Turn the connector off and back on immediately, which
  89. * will trigger link training
  90. */
  91. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  92. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  93. }
  94. }
  95. }
  96. static void radeon_property_change_mode(struct drm_encoder *encoder)
  97. {
  98. struct drm_crtc *crtc = encoder->crtc;
  99. if (crtc && crtc->enabled) {
  100. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  101. crtc->x, crtc->y, crtc->primary->fb);
  102. }
  103. }
  104. int radeon_get_monitor_bpc(struct drm_connector *connector)
  105. {
  106. struct drm_device *dev = connector->dev;
  107. struct radeon_device *rdev = dev->dev_private;
  108. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  109. struct radeon_connector_atom_dig *dig_connector;
  110. int bpc = 8;
  111. int mode_clock, max_tmds_clock;
  112. switch (connector->connector_type) {
  113. case DRM_MODE_CONNECTOR_DVII:
  114. case DRM_MODE_CONNECTOR_HDMIB:
  115. if (radeon_connector->use_digital) {
  116. if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  117. if (connector->display_info.bpc)
  118. bpc = connector->display_info.bpc;
  119. }
  120. }
  121. break;
  122. case DRM_MODE_CONNECTOR_DVID:
  123. case DRM_MODE_CONNECTOR_HDMIA:
  124. if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  125. if (connector->display_info.bpc)
  126. bpc = connector->display_info.bpc;
  127. }
  128. break;
  129. case DRM_MODE_CONNECTOR_DisplayPort:
  130. dig_connector = radeon_connector->con_priv;
  131. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  132. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
  133. drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  134. if (connector->display_info.bpc)
  135. bpc = connector->display_info.bpc;
  136. }
  137. break;
  138. case DRM_MODE_CONNECTOR_eDP:
  139. case DRM_MODE_CONNECTOR_LVDS:
  140. if (connector->display_info.bpc)
  141. bpc = connector->display_info.bpc;
  142. else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  143. const struct drm_connector_helper_funcs *connector_funcs =
  144. connector->helper_private;
  145. struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
  146. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  147. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  148. if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
  149. bpc = 6;
  150. else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
  151. bpc = 8;
  152. }
  153. break;
  154. }
  155. if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  156. /* hdmi deep color only implemented on DCE4+ */
  157. if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
  158. DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
  159. connector->name, bpc);
  160. bpc = 8;
  161. }
  162. /*
  163. * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
  164. * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
  165. * 12 bpc is always supported on hdmi deep color sinks, as this is
  166. * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
  167. */
  168. if (bpc > 12) {
  169. DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
  170. connector->name, bpc);
  171. bpc = 12;
  172. }
  173. /* Any defined maximum tmds clock limit we must not exceed? */
  174. if (connector->max_tmds_clock > 0) {
  175. /* mode_clock is clock in kHz for mode to be modeset on this connector */
  176. mode_clock = radeon_connector->pixelclock_for_modeset;
  177. /* Maximum allowable input clock in kHz */
  178. max_tmds_clock = connector->max_tmds_clock * 1000;
  179. DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
  180. connector->name, mode_clock, max_tmds_clock);
  181. /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
  182. if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
  183. if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
  184. (mode_clock * 5/4 <= max_tmds_clock))
  185. bpc = 10;
  186. else
  187. bpc = 8;
  188. DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
  189. connector->name, bpc);
  190. }
  191. if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
  192. bpc = 8;
  193. DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
  194. connector->name, bpc);
  195. }
  196. }
  197. else if (bpc > 8) {
  198. /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
  199. DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
  200. connector->name);
  201. bpc = 8;
  202. }
  203. }
  204. if ((radeon_deep_color == 0) && (bpc > 8)) {
  205. DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
  206. connector->name);
  207. bpc = 8;
  208. }
  209. DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
  210. connector->name, connector->display_info.bpc, bpc);
  211. return bpc;
  212. }
  213. static void
  214. radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
  215. {
  216. struct drm_device *dev = connector->dev;
  217. struct radeon_device *rdev = dev->dev_private;
  218. struct drm_encoder *best_encoder = NULL;
  219. struct drm_encoder *encoder = NULL;
  220. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  221. bool connected;
  222. int i;
  223. best_encoder = connector_funcs->best_encoder(connector);
  224. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  225. if (connector->encoder_ids[i] == 0)
  226. break;
  227. encoder = drm_encoder_find(connector->dev,
  228. connector->encoder_ids[i]);
  229. if (!encoder)
  230. continue;
  231. if ((encoder == best_encoder) && (status == connector_status_connected))
  232. connected = true;
  233. else
  234. connected = false;
  235. if (rdev->is_atom_bios)
  236. radeon_atombios_connected_scratch_regs(connector, encoder, connected);
  237. else
  238. radeon_combios_connected_scratch_regs(connector, encoder, connected);
  239. }
  240. }
  241. static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
  242. {
  243. struct drm_encoder *encoder;
  244. int i;
  245. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  246. if (connector->encoder_ids[i] == 0)
  247. break;
  248. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  249. if (!encoder)
  250. continue;
  251. if (encoder->encoder_type == encoder_type)
  252. return encoder;
  253. }
  254. return NULL;
  255. }
  256. struct edid *radeon_connector_edid(struct drm_connector *connector)
  257. {
  258. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  259. struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
  260. if (radeon_connector->edid) {
  261. return radeon_connector->edid;
  262. } else if (edid_blob) {
  263. struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
  264. if (edid)
  265. radeon_connector->edid = edid;
  266. }
  267. return radeon_connector->edid;
  268. }
  269. static void radeon_connector_get_edid(struct drm_connector *connector)
  270. {
  271. struct drm_device *dev = connector->dev;
  272. struct radeon_device *rdev = dev->dev_private;
  273. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  274. if (radeon_connector->edid)
  275. return;
  276. /* on hw with routers, select right port */
  277. if (radeon_connector->router.ddc_valid)
  278. radeon_router_select_ddc_port(radeon_connector);
  279. if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  280. ENCODER_OBJECT_ID_NONE) &&
  281. radeon_connector->ddc_bus->has_aux) {
  282. radeon_connector->edid = drm_get_edid(connector,
  283. &radeon_connector->ddc_bus->aux.ddc);
  284. } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
  285. (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
  286. struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
  287. if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
  288. dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
  289. radeon_connector->ddc_bus->has_aux)
  290. radeon_connector->edid = drm_get_edid(&radeon_connector->base,
  291. &radeon_connector->ddc_bus->aux.ddc);
  292. else if (radeon_connector->ddc_bus)
  293. radeon_connector->edid = drm_get_edid(&radeon_connector->base,
  294. &radeon_connector->ddc_bus->adapter);
  295. } else if (radeon_connector->ddc_bus) {
  296. radeon_connector->edid = drm_get_edid(&radeon_connector->base,
  297. &radeon_connector->ddc_bus->adapter);
  298. }
  299. if (!radeon_connector->edid) {
  300. /* don't fetch the edid from the vbios if ddc fails and runpm is
  301. * enabled so we report disconnected.
  302. */
  303. if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
  304. return;
  305. if (rdev->is_atom_bios) {
  306. /* some laptops provide a hardcoded edid in rom for LCDs */
  307. if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
  308. (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
  309. radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
  310. } else {
  311. /* some servers provide a hardcoded edid in rom for KVMs */
  312. radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
  313. }
  314. }
  315. }
  316. static void radeon_connector_free_edid(struct drm_connector *connector)
  317. {
  318. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  319. if (radeon_connector->edid) {
  320. kfree(radeon_connector->edid);
  321. radeon_connector->edid = NULL;
  322. }
  323. }
  324. static int radeon_ddc_get_modes(struct drm_connector *connector)
  325. {
  326. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  327. int ret;
  328. if (radeon_connector->edid) {
  329. drm_mode_connector_update_edid_property(connector, radeon_connector->edid);
  330. ret = drm_add_edid_modes(connector, radeon_connector->edid);
  331. drm_edid_to_eld(connector, radeon_connector->edid);
  332. return ret;
  333. }
  334. drm_mode_connector_update_edid_property(connector, NULL);
  335. return 0;
  336. }
  337. static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
  338. {
  339. int enc_id = connector->encoder_ids[0];
  340. /* pick the encoder ids */
  341. if (enc_id)
  342. return drm_encoder_find(connector->dev, enc_id);
  343. return NULL;
  344. }
  345. static void radeon_get_native_mode(struct drm_connector *connector)
  346. {
  347. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  348. struct radeon_encoder *radeon_encoder;
  349. if (encoder == NULL)
  350. return;
  351. radeon_encoder = to_radeon_encoder(encoder);
  352. if (!list_empty(&connector->probed_modes)) {
  353. struct drm_display_mode *preferred_mode =
  354. list_first_entry(&connector->probed_modes,
  355. struct drm_display_mode, head);
  356. radeon_encoder->native_mode = *preferred_mode;
  357. } else {
  358. radeon_encoder->native_mode.clock = 0;
  359. }
  360. }
  361. /*
  362. * radeon_connector_analog_encoder_conflict_solve
  363. * - search for other connectors sharing this encoder
  364. * if priority is true, then set them disconnected if this is connected
  365. * if priority is false, set us disconnected if they are connected
  366. */
  367. static enum drm_connector_status
  368. radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
  369. struct drm_encoder *encoder,
  370. enum drm_connector_status current_status,
  371. bool priority)
  372. {
  373. struct drm_device *dev = connector->dev;
  374. struct drm_connector *conflict;
  375. struct radeon_connector *radeon_conflict;
  376. int i;
  377. list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
  378. if (conflict == connector)
  379. continue;
  380. radeon_conflict = to_radeon_connector(conflict);
  381. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  382. if (conflict->encoder_ids[i] == 0)
  383. break;
  384. /* if the IDs match */
  385. if (conflict->encoder_ids[i] == encoder->base.id) {
  386. if (conflict->status != connector_status_connected)
  387. continue;
  388. if (radeon_conflict->use_digital)
  389. continue;
  390. if (priority == true) {
  391. DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
  392. conflict->name);
  393. DRM_DEBUG_KMS("in favor of %s\n",
  394. connector->name);
  395. conflict->status = connector_status_disconnected;
  396. radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
  397. } else {
  398. DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
  399. connector->name);
  400. DRM_DEBUG_KMS("in favor of %s\n",
  401. conflict->name);
  402. current_status = connector_status_disconnected;
  403. }
  404. break;
  405. }
  406. }
  407. }
  408. return current_status;
  409. }
  410. static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
  411. {
  412. struct drm_device *dev = encoder->dev;
  413. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  414. struct drm_display_mode *mode = NULL;
  415. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  416. if (native_mode->hdisplay != 0 &&
  417. native_mode->vdisplay != 0 &&
  418. native_mode->clock != 0) {
  419. mode = drm_mode_duplicate(dev, native_mode);
  420. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  421. drm_mode_set_name(mode);
  422. DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
  423. } else if (native_mode->hdisplay != 0 &&
  424. native_mode->vdisplay != 0) {
  425. /* mac laptops without an edid */
  426. /* Note that this is not necessarily the exact panel mode,
  427. * but an approximation based on the cvt formula. For these
  428. * systems we should ideally read the mode info out of the
  429. * registers or add a mode table, but this works and is much
  430. * simpler.
  431. */
  432. mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
  433. mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
  434. DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
  435. }
  436. return mode;
  437. }
  438. static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
  439. {
  440. struct drm_device *dev = encoder->dev;
  441. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  442. struct drm_display_mode *mode = NULL;
  443. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  444. int i;
  445. struct mode_size {
  446. int w;
  447. int h;
  448. } common_modes[17] = {
  449. { 640, 480},
  450. { 720, 480},
  451. { 800, 600},
  452. { 848, 480},
  453. {1024, 768},
  454. {1152, 768},
  455. {1280, 720},
  456. {1280, 800},
  457. {1280, 854},
  458. {1280, 960},
  459. {1280, 1024},
  460. {1440, 900},
  461. {1400, 1050},
  462. {1680, 1050},
  463. {1600, 1200},
  464. {1920, 1080},
  465. {1920, 1200}
  466. };
  467. for (i = 0; i < 17; i++) {
  468. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  469. if (common_modes[i].w > 1024 ||
  470. common_modes[i].h > 768)
  471. continue;
  472. }
  473. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  474. if (common_modes[i].w > native_mode->hdisplay ||
  475. common_modes[i].h > native_mode->vdisplay ||
  476. (common_modes[i].w == native_mode->hdisplay &&
  477. common_modes[i].h == native_mode->vdisplay))
  478. continue;
  479. }
  480. if (common_modes[i].w < 320 || common_modes[i].h < 200)
  481. continue;
  482. mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
  483. drm_mode_probed_add(connector, mode);
  484. }
  485. }
  486. static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
  487. uint64_t val)
  488. {
  489. struct drm_device *dev = connector->dev;
  490. struct radeon_device *rdev = dev->dev_private;
  491. struct drm_encoder *encoder;
  492. struct radeon_encoder *radeon_encoder;
  493. if (property == rdev->mode_info.coherent_mode_property) {
  494. struct radeon_encoder_atom_dig *dig;
  495. bool new_coherent_mode;
  496. /* need to find digital encoder on connector */
  497. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  498. if (!encoder)
  499. return 0;
  500. radeon_encoder = to_radeon_encoder(encoder);
  501. if (!radeon_encoder->enc_priv)
  502. return 0;
  503. dig = radeon_encoder->enc_priv;
  504. new_coherent_mode = val ? true : false;
  505. if (dig->coherent_mode != new_coherent_mode) {
  506. dig->coherent_mode = new_coherent_mode;
  507. radeon_property_change_mode(&radeon_encoder->base);
  508. }
  509. }
  510. if (property == rdev->mode_info.audio_property) {
  511. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  512. /* need to find digital encoder on connector */
  513. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  514. if (!encoder)
  515. return 0;
  516. radeon_encoder = to_radeon_encoder(encoder);
  517. if (radeon_connector->audio != val) {
  518. radeon_connector->audio = val;
  519. radeon_property_change_mode(&radeon_encoder->base);
  520. }
  521. }
  522. if (property == rdev->mode_info.dither_property) {
  523. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  524. /* need to find digital encoder on connector */
  525. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  526. if (!encoder)
  527. return 0;
  528. radeon_encoder = to_radeon_encoder(encoder);
  529. if (radeon_connector->dither != val) {
  530. radeon_connector->dither = val;
  531. radeon_property_change_mode(&radeon_encoder->base);
  532. }
  533. }
  534. if (property == rdev->mode_info.underscan_property) {
  535. /* need to find digital encoder on connector */
  536. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  537. if (!encoder)
  538. return 0;
  539. radeon_encoder = to_radeon_encoder(encoder);
  540. if (radeon_encoder->underscan_type != val) {
  541. radeon_encoder->underscan_type = val;
  542. radeon_property_change_mode(&radeon_encoder->base);
  543. }
  544. }
  545. if (property == rdev->mode_info.underscan_hborder_property) {
  546. /* need to find digital encoder on connector */
  547. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  548. if (!encoder)
  549. return 0;
  550. radeon_encoder = to_radeon_encoder(encoder);
  551. if (radeon_encoder->underscan_hborder != val) {
  552. radeon_encoder->underscan_hborder = val;
  553. radeon_property_change_mode(&radeon_encoder->base);
  554. }
  555. }
  556. if (property == rdev->mode_info.underscan_vborder_property) {
  557. /* need to find digital encoder on connector */
  558. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  559. if (!encoder)
  560. return 0;
  561. radeon_encoder = to_radeon_encoder(encoder);
  562. if (radeon_encoder->underscan_vborder != val) {
  563. radeon_encoder->underscan_vborder = val;
  564. radeon_property_change_mode(&radeon_encoder->base);
  565. }
  566. }
  567. if (property == rdev->mode_info.tv_std_property) {
  568. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
  569. if (!encoder) {
  570. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
  571. }
  572. if (!encoder)
  573. return 0;
  574. radeon_encoder = to_radeon_encoder(encoder);
  575. if (!radeon_encoder->enc_priv)
  576. return 0;
  577. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
  578. struct radeon_encoder_atom_dac *dac_int;
  579. dac_int = radeon_encoder->enc_priv;
  580. dac_int->tv_std = val;
  581. } else {
  582. struct radeon_encoder_tv_dac *dac_int;
  583. dac_int = radeon_encoder->enc_priv;
  584. dac_int->tv_std = val;
  585. }
  586. radeon_property_change_mode(&radeon_encoder->base);
  587. }
  588. if (property == rdev->mode_info.load_detect_property) {
  589. struct radeon_connector *radeon_connector =
  590. to_radeon_connector(connector);
  591. if (val == 0)
  592. radeon_connector->dac_load_detect = false;
  593. else
  594. radeon_connector->dac_load_detect = true;
  595. }
  596. if (property == rdev->mode_info.tmds_pll_property) {
  597. struct radeon_encoder_int_tmds *tmds = NULL;
  598. bool ret = false;
  599. /* need to find digital encoder on connector */
  600. encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
  601. if (!encoder)
  602. return 0;
  603. radeon_encoder = to_radeon_encoder(encoder);
  604. tmds = radeon_encoder->enc_priv;
  605. if (!tmds)
  606. return 0;
  607. if (val == 0) {
  608. if (rdev->is_atom_bios)
  609. ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
  610. else
  611. ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
  612. }
  613. if (val == 1 || ret == false) {
  614. radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
  615. }
  616. radeon_property_change_mode(&radeon_encoder->base);
  617. }
  618. if (property == dev->mode_config.scaling_mode_property) {
  619. enum radeon_rmx_type rmx_type;
  620. if (connector->encoder)
  621. radeon_encoder = to_radeon_encoder(connector->encoder);
  622. else {
  623. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  624. radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
  625. }
  626. switch (val) {
  627. default:
  628. case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
  629. case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
  630. case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
  631. case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
  632. }
  633. if (radeon_encoder->rmx_type == rmx_type)
  634. return 0;
  635. if ((rmx_type != DRM_MODE_SCALE_NONE) &&
  636. (radeon_encoder->native_mode.clock == 0))
  637. return 0;
  638. radeon_encoder->rmx_type = rmx_type;
  639. radeon_property_change_mode(&radeon_encoder->base);
  640. }
  641. if (property == rdev->mode_info.output_csc_property) {
  642. if (connector->encoder)
  643. radeon_encoder = to_radeon_encoder(connector->encoder);
  644. else {
  645. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  646. radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
  647. }
  648. if (radeon_encoder->output_csc == val)
  649. return 0;
  650. radeon_encoder->output_csc = val;
  651. if (connector->encoder->crtc) {
  652. struct drm_crtc *crtc = connector->encoder->crtc;
  653. const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  654. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  655. radeon_crtc->output_csc = radeon_encoder->output_csc;
  656. (*crtc_funcs->load_lut)(crtc);
  657. }
  658. }
  659. return 0;
  660. }
  661. static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
  662. struct drm_connector *connector)
  663. {
  664. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  665. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  666. struct drm_display_mode *t, *mode;
  667. /* If the EDID preferred mode doesn't match the native mode, use it */
  668. list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
  669. if (mode->type & DRM_MODE_TYPE_PREFERRED) {
  670. if (mode->hdisplay != native_mode->hdisplay ||
  671. mode->vdisplay != native_mode->vdisplay)
  672. memcpy(native_mode, mode, sizeof(*mode));
  673. }
  674. }
  675. /* Try to get native mode details from EDID if necessary */
  676. if (!native_mode->clock) {
  677. list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
  678. if (mode->hdisplay == native_mode->hdisplay &&
  679. mode->vdisplay == native_mode->vdisplay) {
  680. *native_mode = *mode;
  681. drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
  682. DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
  683. break;
  684. }
  685. }
  686. }
  687. if (!native_mode->clock) {
  688. DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
  689. radeon_encoder->rmx_type = RMX_OFF;
  690. }
  691. }
  692. static int radeon_lvds_get_modes(struct drm_connector *connector)
  693. {
  694. struct drm_encoder *encoder;
  695. int ret = 0;
  696. struct drm_display_mode *mode;
  697. radeon_connector_get_edid(connector);
  698. ret = radeon_ddc_get_modes(connector);
  699. if (ret > 0) {
  700. encoder = radeon_best_single_encoder(connector);
  701. if (encoder) {
  702. radeon_fixup_lvds_native_mode(encoder, connector);
  703. /* add scaled modes */
  704. radeon_add_common_modes(encoder, connector);
  705. }
  706. return ret;
  707. }
  708. encoder = radeon_best_single_encoder(connector);
  709. if (!encoder)
  710. return 0;
  711. /* we have no EDID modes */
  712. mode = radeon_fp_native_mode(encoder);
  713. if (mode) {
  714. ret = 1;
  715. drm_mode_probed_add(connector, mode);
  716. /* add the width/height from vbios tables if available */
  717. connector->display_info.width_mm = mode->width_mm;
  718. connector->display_info.height_mm = mode->height_mm;
  719. /* add scaled modes */
  720. radeon_add_common_modes(encoder, connector);
  721. }
  722. return ret;
  723. }
  724. static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
  725. struct drm_display_mode *mode)
  726. {
  727. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  728. if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
  729. return MODE_PANEL;
  730. if (encoder) {
  731. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  732. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  733. /* AVIVO hardware supports downscaling modes larger than the panel
  734. * to the panel size, but I'm not sure this is desirable.
  735. */
  736. if ((mode->hdisplay > native_mode->hdisplay) ||
  737. (mode->vdisplay > native_mode->vdisplay))
  738. return MODE_PANEL;
  739. /* if scaling is disabled, block non-native modes */
  740. if (radeon_encoder->rmx_type == RMX_OFF) {
  741. if ((mode->hdisplay != native_mode->hdisplay) ||
  742. (mode->vdisplay != native_mode->vdisplay))
  743. return MODE_PANEL;
  744. }
  745. }
  746. return MODE_OK;
  747. }
  748. static enum drm_connector_status
  749. radeon_lvds_detect(struct drm_connector *connector, bool force)
  750. {
  751. struct drm_device *dev = connector->dev;
  752. struct radeon_device *rdev = dev->dev_private;
  753. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  754. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  755. enum drm_connector_status ret = connector_status_disconnected;
  756. int r;
  757. if (!drm_kms_helper_is_poll_worker()) {
  758. r = pm_runtime_get_sync(connector->dev->dev);
  759. if (r < 0)
  760. return connector_status_disconnected;
  761. }
  762. if (encoder) {
  763. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  764. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  765. /* check if panel is valid */
  766. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  767. ret = connector_status_connected;
  768. /* don't fetch the edid from the vbios if ddc fails and runpm is
  769. * enabled so we report disconnected.
  770. */
  771. if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
  772. ret = connector_status_disconnected;
  773. }
  774. /* check for edid as well */
  775. radeon_connector_get_edid(connector);
  776. if (radeon_connector->edid)
  777. ret = connector_status_connected;
  778. /* check acpi lid status ??? */
  779. radeon_connector_update_scratch_regs(connector, ret);
  780. if (!drm_kms_helper_is_poll_worker()) {
  781. pm_runtime_mark_last_busy(connector->dev->dev);
  782. pm_runtime_put_autosuspend(connector->dev->dev);
  783. }
  784. return ret;
  785. }
  786. static void radeon_connector_destroy(struct drm_connector *connector)
  787. {
  788. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  789. radeon_connector_free_edid(connector);
  790. kfree(radeon_connector->con_priv);
  791. drm_connector_unregister(connector);
  792. drm_connector_cleanup(connector);
  793. kfree(connector);
  794. }
  795. static int radeon_lvds_set_property(struct drm_connector *connector,
  796. struct drm_property *property,
  797. uint64_t value)
  798. {
  799. struct drm_device *dev = connector->dev;
  800. struct radeon_encoder *radeon_encoder;
  801. enum radeon_rmx_type rmx_type;
  802. DRM_DEBUG_KMS("\n");
  803. if (property != dev->mode_config.scaling_mode_property)
  804. return 0;
  805. if (connector->encoder)
  806. radeon_encoder = to_radeon_encoder(connector->encoder);
  807. else {
  808. const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
  809. radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
  810. }
  811. switch (value) {
  812. case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
  813. case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
  814. case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
  815. default:
  816. case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
  817. }
  818. if (radeon_encoder->rmx_type == rmx_type)
  819. return 0;
  820. radeon_encoder->rmx_type = rmx_type;
  821. radeon_property_change_mode(&radeon_encoder->base);
  822. return 0;
  823. }
  824. static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
  825. .get_modes = radeon_lvds_get_modes,
  826. .mode_valid = radeon_lvds_mode_valid,
  827. .best_encoder = radeon_best_single_encoder,
  828. };
  829. static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
  830. .dpms = drm_helper_connector_dpms,
  831. .detect = radeon_lvds_detect,
  832. .fill_modes = drm_helper_probe_single_connector_modes,
  833. .destroy = radeon_connector_destroy,
  834. .set_property = radeon_lvds_set_property,
  835. };
  836. static int radeon_vga_get_modes(struct drm_connector *connector)
  837. {
  838. int ret;
  839. radeon_connector_get_edid(connector);
  840. ret = radeon_ddc_get_modes(connector);
  841. radeon_get_native_mode(connector);
  842. return ret;
  843. }
  844. static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
  845. struct drm_display_mode *mode)
  846. {
  847. struct drm_device *dev = connector->dev;
  848. struct radeon_device *rdev = dev->dev_private;
  849. /* XXX check mode bandwidth */
  850. if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
  851. return MODE_CLOCK_HIGH;
  852. return MODE_OK;
  853. }
  854. static enum drm_connector_status
  855. radeon_vga_detect(struct drm_connector *connector, bool force)
  856. {
  857. struct drm_device *dev = connector->dev;
  858. struct radeon_device *rdev = dev->dev_private;
  859. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  860. struct drm_encoder *encoder;
  861. const struct drm_encoder_helper_funcs *encoder_funcs;
  862. bool dret = false;
  863. enum drm_connector_status ret = connector_status_disconnected;
  864. int r;
  865. if (!drm_kms_helper_is_poll_worker()) {
  866. r = pm_runtime_get_sync(connector->dev->dev);
  867. if (r < 0)
  868. return connector_status_disconnected;
  869. }
  870. encoder = radeon_best_single_encoder(connector);
  871. if (!encoder)
  872. ret = connector_status_disconnected;
  873. if (radeon_connector->ddc_bus)
  874. dret = radeon_ddc_probe(radeon_connector, false);
  875. if (dret) {
  876. radeon_connector->detected_by_load = false;
  877. radeon_connector_free_edid(connector);
  878. radeon_connector_get_edid(connector);
  879. if (!radeon_connector->edid) {
  880. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  881. connector->name);
  882. ret = connector_status_connected;
  883. } else {
  884. radeon_connector->use_digital =
  885. !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  886. /* some oems have boards with separate digital and analog connectors
  887. * with a shared ddc line (often vga + hdmi)
  888. */
  889. if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
  890. radeon_connector_free_edid(connector);
  891. ret = connector_status_disconnected;
  892. } else {
  893. ret = connector_status_connected;
  894. }
  895. }
  896. } else {
  897. /* if we aren't forcing don't do destructive polling */
  898. if (!force) {
  899. /* only return the previous status if we last
  900. * detected a monitor via load.
  901. */
  902. if (radeon_connector->detected_by_load)
  903. ret = connector->status;
  904. goto out;
  905. }
  906. if (radeon_connector->dac_load_detect && encoder) {
  907. encoder_funcs = encoder->helper_private;
  908. ret = encoder_funcs->detect(encoder, connector);
  909. if (ret != connector_status_disconnected)
  910. radeon_connector->detected_by_load = true;
  911. }
  912. }
  913. if (ret == connector_status_connected)
  914. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
  915. /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
  916. * vbios to deal with KVMs. If we have one and are not able to detect a monitor
  917. * by other means, assume the CRT is connected and use that EDID.
  918. */
  919. if ((!rdev->is_atom_bios) &&
  920. (ret == connector_status_disconnected) &&
  921. rdev->mode_info.bios_hardcoded_edid_size) {
  922. ret = connector_status_connected;
  923. }
  924. radeon_connector_update_scratch_regs(connector, ret);
  925. out:
  926. if (!drm_kms_helper_is_poll_worker()) {
  927. pm_runtime_mark_last_busy(connector->dev->dev);
  928. pm_runtime_put_autosuspend(connector->dev->dev);
  929. }
  930. return ret;
  931. }
  932. static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
  933. .get_modes = radeon_vga_get_modes,
  934. .mode_valid = radeon_vga_mode_valid,
  935. .best_encoder = radeon_best_single_encoder,
  936. };
  937. static const struct drm_connector_funcs radeon_vga_connector_funcs = {
  938. .dpms = drm_helper_connector_dpms,
  939. .detect = radeon_vga_detect,
  940. .fill_modes = drm_helper_probe_single_connector_modes,
  941. .destroy = radeon_connector_destroy,
  942. .set_property = radeon_connector_set_property,
  943. };
  944. static int radeon_tv_get_modes(struct drm_connector *connector)
  945. {
  946. struct drm_device *dev = connector->dev;
  947. struct radeon_device *rdev = dev->dev_private;
  948. struct drm_display_mode *tv_mode;
  949. struct drm_encoder *encoder;
  950. encoder = radeon_best_single_encoder(connector);
  951. if (!encoder)
  952. return 0;
  953. /* avivo chips can scale any mode */
  954. if (rdev->family >= CHIP_RS600)
  955. /* add scaled modes */
  956. radeon_add_common_modes(encoder, connector);
  957. else {
  958. /* only 800x600 is supported right now on pre-avivo chips */
  959. tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
  960. tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  961. drm_mode_probed_add(connector, tv_mode);
  962. }
  963. return 1;
  964. }
  965. static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector,
  966. struct drm_display_mode *mode)
  967. {
  968. if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
  969. return MODE_CLOCK_RANGE;
  970. return MODE_OK;
  971. }
  972. static enum drm_connector_status
  973. radeon_tv_detect(struct drm_connector *connector, bool force)
  974. {
  975. struct drm_encoder *encoder;
  976. const struct drm_encoder_helper_funcs *encoder_funcs;
  977. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  978. enum drm_connector_status ret = connector_status_disconnected;
  979. int r;
  980. if (!radeon_connector->dac_load_detect)
  981. return ret;
  982. if (!drm_kms_helper_is_poll_worker()) {
  983. r = pm_runtime_get_sync(connector->dev->dev);
  984. if (r < 0)
  985. return connector_status_disconnected;
  986. }
  987. encoder = radeon_best_single_encoder(connector);
  988. if (!encoder)
  989. ret = connector_status_disconnected;
  990. else {
  991. encoder_funcs = encoder->helper_private;
  992. ret = encoder_funcs->detect(encoder, connector);
  993. }
  994. if (ret == connector_status_connected)
  995. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
  996. radeon_connector_update_scratch_regs(connector, ret);
  997. if (!drm_kms_helper_is_poll_worker()) {
  998. pm_runtime_mark_last_busy(connector->dev->dev);
  999. pm_runtime_put_autosuspend(connector->dev->dev);
  1000. }
  1001. return ret;
  1002. }
  1003. static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
  1004. .get_modes = radeon_tv_get_modes,
  1005. .mode_valid = radeon_tv_mode_valid,
  1006. .best_encoder = radeon_best_single_encoder,
  1007. };
  1008. static const struct drm_connector_funcs radeon_tv_connector_funcs = {
  1009. .dpms = drm_helper_connector_dpms,
  1010. .detect = radeon_tv_detect,
  1011. .fill_modes = drm_helper_probe_single_connector_modes,
  1012. .destroy = radeon_connector_destroy,
  1013. .set_property = radeon_connector_set_property,
  1014. };
  1015. static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
  1016. {
  1017. struct drm_device *dev = connector->dev;
  1018. struct radeon_device *rdev = dev->dev_private;
  1019. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1020. enum drm_connector_status status;
  1021. /* We only trust HPD on R600 and newer ASICS. */
  1022. if (rdev->family >= CHIP_R600
  1023. && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
  1024. if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
  1025. status = connector_status_connected;
  1026. else
  1027. status = connector_status_disconnected;
  1028. if (connector->status == status)
  1029. return true;
  1030. }
  1031. return false;
  1032. }
  1033. /*
  1034. * DVI is complicated
  1035. * Do a DDC probe, if DDC probe passes, get the full EDID so
  1036. * we can do analog/digital monitor detection at this point.
  1037. * If the monitor is an analog monitor or we got no DDC,
  1038. * we need to find the DAC encoder object for this connector.
  1039. * If we got no DDC, we do load detection on the DAC encoder object.
  1040. * If we got analog DDC or load detection passes on the DAC encoder
  1041. * we have to check if this analog encoder is shared with anyone else (TV)
  1042. * if its shared we have to set the other connector to disconnected.
  1043. */
  1044. static enum drm_connector_status
  1045. radeon_dvi_detect(struct drm_connector *connector, bool force)
  1046. {
  1047. struct drm_device *dev = connector->dev;
  1048. struct radeon_device *rdev = dev->dev_private;
  1049. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1050. struct drm_encoder *encoder = NULL;
  1051. const struct drm_encoder_helper_funcs *encoder_funcs;
  1052. int i, r;
  1053. enum drm_connector_status ret = connector_status_disconnected;
  1054. bool dret = false, broken_edid = false;
  1055. if (!drm_kms_helper_is_poll_worker()) {
  1056. r = pm_runtime_get_sync(connector->dev->dev);
  1057. if (r < 0)
  1058. return connector_status_disconnected;
  1059. }
  1060. if (radeon_connector->detected_hpd_without_ddc) {
  1061. force = true;
  1062. radeon_connector->detected_hpd_without_ddc = false;
  1063. }
  1064. if (!force && radeon_check_hpd_status_unchanged(connector)) {
  1065. ret = connector->status;
  1066. goto exit;
  1067. }
  1068. if (radeon_connector->ddc_bus) {
  1069. dret = radeon_ddc_probe(radeon_connector, false);
  1070. /* Sometimes the pins required for the DDC probe on DVI
  1071. * connectors don't make contact at the same time that the ones
  1072. * for HPD do. If the DDC probe fails even though we had an HPD
  1073. * signal, try again later */
  1074. if (!dret && !force &&
  1075. connector->status != connector_status_connected) {
  1076. DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
  1077. radeon_connector->detected_hpd_without_ddc = true;
  1078. schedule_delayed_work(&rdev->hotplug_work,
  1079. msecs_to_jiffies(1000));
  1080. goto exit;
  1081. }
  1082. }
  1083. if (dret) {
  1084. radeon_connector->detected_by_load = false;
  1085. radeon_connector_free_edid(connector);
  1086. radeon_connector_get_edid(connector);
  1087. if (!radeon_connector->edid) {
  1088. DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
  1089. connector->name);
  1090. /* rs690 seems to have a problem with connectors not existing and always
  1091. * return a block of 0's. If we see this just stop polling on this output */
  1092. if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
  1093. radeon_connector->base.null_edid_counter) {
  1094. ret = connector_status_disconnected;
  1095. DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
  1096. connector->name);
  1097. radeon_connector->ddc_bus = NULL;
  1098. } else {
  1099. ret = connector_status_connected;
  1100. broken_edid = true; /* defer use_digital to later */
  1101. }
  1102. } else {
  1103. radeon_connector->use_digital =
  1104. !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
  1105. /* some oems have boards with separate digital and analog connectors
  1106. * with a shared ddc line (often vga + hdmi)
  1107. */
  1108. if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
  1109. radeon_connector_free_edid(connector);
  1110. ret = connector_status_disconnected;
  1111. } else {
  1112. ret = connector_status_connected;
  1113. }
  1114. /* This gets complicated. We have boards with VGA + HDMI with a
  1115. * shared DDC line and we have boards with DVI-D + HDMI with a shared
  1116. * DDC line. The latter is more complex because with DVI<->HDMI adapters
  1117. * you don't really know what's connected to which port as both are digital.
  1118. */
  1119. if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
  1120. struct drm_connector *list_connector;
  1121. struct radeon_connector *list_radeon_connector;
  1122. list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
  1123. if (connector == list_connector)
  1124. continue;
  1125. list_radeon_connector = to_radeon_connector(list_connector);
  1126. if (list_radeon_connector->shared_ddc &&
  1127. (list_radeon_connector->ddc_bus->rec.i2c_id ==
  1128. radeon_connector->ddc_bus->rec.i2c_id)) {
  1129. /* cases where both connectors are digital */
  1130. if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
  1131. /* hpd is our only option in this case */
  1132. if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
  1133. radeon_connector_free_edid(connector);
  1134. ret = connector_status_disconnected;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
  1143. goto out;
  1144. /* DVI-D and HDMI-A are digital only */
  1145. if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
  1146. (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
  1147. goto out;
  1148. /* if we aren't forcing don't do destructive polling */
  1149. if (!force) {
  1150. /* only return the previous status if we last
  1151. * detected a monitor via load.
  1152. */
  1153. if (radeon_connector->detected_by_load)
  1154. ret = connector->status;
  1155. goto out;
  1156. }
  1157. /* find analog encoder */
  1158. if (radeon_connector->dac_load_detect) {
  1159. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1160. if (connector->encoder_ids[i] == 0)
  1161. break;
  1162. encoder = drm_encoder_find(connector->dev,
  1163. connector->encoder_ids[i]);
  1164. if (!encoder)
  1165. continue;
  1166. if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
  1167. encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
  1168. continue;
  1169. encoder_funcs = encoder->helper_private;
  1170. if (encoder_funcs->detect) {
  1171. if (!broken_edid) {
  1172. if (ret != connector_status_connected) {
  1173. /* deal with analog monitors without DDC */
  1174. ret = encoder_funcs->detect(encoder, connector);
  1175. if (ret == connector_status_connected) {
  1176. radeon_connector->use_digital = false;
  1177. }
  1178. if (ret != connector_status_disconnected)
  1179. radeon_connector->detected_by_load = true;
  1180. }
  1181. } else {
  1182. enum drm_connector_status lret;
  1183. /* assume digital unless load detected otherwise */
  1184. radeon_connector->use_digital = true;
  1185. lret = encoder_funcs->detect(encoder, connector);
  1186. DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
  1187. if (lret == connector_status_connected)
  1188. radeon_connector->use_digital = false;
  1189. }
  1190. break;
  1191. }
  1192. }
  1193. }
  1194. if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
  1195. encoder) {
  1196. ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
  1197. }
  1198. /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
  1199. * vbios to deal with KVMs. If we have one and are not able to detect a monitor
  1200. * by other means, assume the DFP is connected and use that EDID. In most
  1201. * cases the DVI port is actually a virtual KVM port connected to the service
  1202. * processor.
  1203. */
  1204. out:
  1205. if ((!rdev->is_atom_bios) &&
  1206. (ret == connector_status_disconnected) &&
  1207. rdev->mode_info.bios_hardcoded_edid_size) {
  1208. radeon_connector->use_digital = true;
  1209. ret = connector_status_connected;
  1210. }
  1211. /* updated in get modes as well since we need to know if it's analog or digital */
  1212. radeon_connector_update_scratch_regs(connector, ret);
  1213. if ((radeon_audio != 0) && radeon_connector->use_digital) {
  1214. const struct drm_connector_helper_funcs *connector_funcs =
  1215. connector->helper_private;
  1216. encoder = connector_funcs->best_encoder(connector);
  1217. if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
  1218. radeon_connector_get_edid(connector);
  1219. radeon_audio_detect(connector, encoder, ret);
  1220. }
  1221. }
  1222. exit:
  1223. if (!drm_kms_helper_is_poll_worker()) {
  1224. pm_runtime_mark_last_busy(connector->dev->dev);
  1225. pm_runtime_put_autosuspend(connector->dev->dev);
  1226. }
  1227. return ret;
  1228. }
  1229. /* okay need to be smart in here about which encoder to pick */
  1230. static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
  1231. {
  1232. int enc_id = connector->encoder_ids[0];
  1233. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1234. struct drm_encoder *encoder;
  1235. int i;
  1236. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1237. if (connector->encoder_ids[i] == 0)
  1238. break;
  1239. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  1240. if (!encoder)
  1241. continue;
  1242. if (radeon_connector->use_digital == true) {
  1243. if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
  1244. return encoder;
  1245. } else {
  1246. if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
  1247. encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
  1248. return encoder;
  1249. }
  1250. }
  1251. /* see if we have a default encoder TODO */
  1252. /* then check use digitial */
  1253. /* pick the first one */
  1254. if (enc_id)
  1255. return drm_encoder_find(connector->dev, enc_id);
  1256. return NULL;
  1257. }
  1258. static void radeon_dvi_force(struct drm_connector *connector)
  1259. {
  1260. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1261. if (connector->force == DRM_FORCE_ON)
  1262. radeon_connector->use_digital = false;
  1263. if (connector->force == DRM_FORCE_ON_DIGITAL)
  1264. radeon_connector->use_digital = true;
  1265. }
  1266. static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
  1267. struct drm_display_mode *mode)
  1268. {
  1269. struct drm_device *dev = connector->dev;
  1270. struct radeon_device *rdev = dev->dev_private;
  1271. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1272. /* XXX check mode bandwidth */
  1273. /* clocks over 135 MHz have heat issues with DVI on RV100 */
  1274. if (radeon_connector->use_digital &&
  1275. (rdev->family == CHIP_RV100) &&
  1276. (mode->clock > 135000))
  1277. return MODE_CLOCK_HIGH;
  1278. if (radeon_connector->use_digital && (mode->clock > 165000)) {
  1279. if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
  1280. (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
  1281. (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
  1282. return MODE_OK;
  1283. else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_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. return MODE_OK;
  1289. } else {
  1290. return MODE_CLOCK_HIGH;
  1291. }
  1292. }
  1293. /* check against the max pixel clock */
  1294. if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
  1295. return MODE_CLOCK_HIGH;
  1296. return MODE_OK;
  1297. }
  1298. static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
  1299. .get_modes = radeon_vga_get_modes,
  1300. .mode_valid = radeon_dvi_mode_valid,
  1301. .best_encoder = radeon_dvi_encoder,
  1302. };
  1303. static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
  1304. .dpms = drm_helper_connector_dpms,
  1305. .detect = radeon_dvi_detect,
  1306. .fill_modes = drm_helper_probe_single_connector_modes,
  1307. .set_property = radeon_connector_set_property,
  1308. .destroy = radeon_connector_destroy,
  1309. .force = radeon_dvi_force,
  1310. };
  1311. static int radeon_dp_get_modes(struct drm_connector *connector)
  1312. {
  1313. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1314. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  1315. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  1316. int ret;
  1317. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1318. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1319. struct drm_display_mode *mode;
  1320. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
  1321. if (!radeon_dig_connector->edp_on)
  1322. atombios_set_edp_panel_power(connector,
  1323. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1324. radeon_connector_get_edid(connector);
  1325. ret = radeon_ddc_get_modes(connector);
  1326. if (!radeon_dig_connector->edp_on)
  1327. atombios_set_edp_panel_power(connector,
  1328. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1329. } else {
  1330. /* need to setup ddc on the bridge */
  1331. if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1332. ENCODER_OBJECT_ID_NONE) {
  1333. if (encoder)
  1334. radeon_atom_ext_encoder_setup_ddc(encoder);
  1335. }
  1336. radeon_connector_get_edid(connector);
  1337. ret = radeon_ddc_get_modes(connector);
  1338. }
  1339. if (ret > 0) {
  1340. if (encoder) {
  1341. radeon_fixup_lvds_native_mode(encoder, connector);
  1342. /* add scaled modes */
  1343. radeon_add_common_modes(encoder, connector);
  1344. }
  1345. return ret;
  1346. }
  1347. if (!encoder)
  1348. return 0;
  1349. /* we have no EDID modes */
  1350. mode = radeon_fp_native_mode(encoder);
  1351. if (mode) {
  1352. ret = 1;
  1353. drm_mode_probed_add(connector, mode);
  1354. /* add the width/height from vbios tables if available */
  1355. connector->display_info.width_mm = mode->width_mm;
  1356. connector->display_info.height_mm = mode->height_mm;
  1357. /* add scaled modes */
  1358. radeon_add_common_modes(encoder, connector);
  1359. }
  1360. } else {
  1361. /* need to setup ddc on the bridge */
  1362. if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1363. ENCODER_OBJECT_ID_NONE) {
  1364. if (encoder)
  1365. radeon_atom_ext_encoder_setup_ddc(encoder);
  1366. }
  1367. radeon_connector_get_edid(connector);
  1368. ret = radeon_ddc_get_modes(connector);
  1369. radeon_get_native_mode(connector);
  1370. }
  1371. return ret;
  1372. }
  1373. u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
  1374. {
  1375. struct drm_encoder *encoder;
  1376. struct radeon_encoder *radeon_encoder;
  1377. int i;
  1378. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1379. if (connector->encoder_ids[i] == 0)
  1380. break;
  1381. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  1382. if (!encoder)
  1383. continue;
  1384. radeon_encoder = to_radeon_encoder(encoder);
  1385. switch (radeon_encoder->encoder_id) {
  1386. case ENCODER_OBJECT_ID_TRAVIS:
  1387. case ENCODER_OBJECT_ID_NUTMEG:
  1388. return radeon_encoder->encoder_id;
  1389. default:
  1390. break;
  1391. }
  1392. }
  1393. return ENCODER_OBJECT_ID_NONE;
  1394. }
  1395. static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
  1396. {
  1397. struct drm_encoder *encoder;
  1398. struct radeon_encoder *radeon_encoder;
  1399. int i;
  1400. bool found = false;
  1401. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1402. if (connector->encoder_ids[i] == 0)
  1403. break;
  1404. encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
  1405. if (!encoder)
  1406. continue;
  1407. radeon_encoder = to_radeon_encoder(encoder);
  1408. if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
  1409. found = true;
  1410. }
  1411. return found;
  1412. }
  1413. bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
  1414. {
  1415. struct drm_device *dev = connector->dev;
  1416. struct radeon_device *rdev = dev->dev_private;
  1417. if (ASIC_IS_DCE5(rdev) &&
  1418. (rdev->clock.default_dispclk >= 53900) &&
  1419. radeon_connector_encoder_is_hbr2(connector)) {
  1420. return true;
  1421. }
  1422. return false;
  1423. }
  1424. static enum drm_connector_status
  1425. radeon_dp_detect(struct drm_connector *connector, bool force)
  1426. {
  1427. struct drm_device *dev = connector->dev;
  1428. struct radeon_device *rdev = dev->dev_private;
  1429. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1430. enum drm_connector_status ret = connector_status_disconnected;
  1431. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  1432. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  1433. int r;
  1434. if (radeon_dig_connector->is_mst)
  1435. return connector_status_disconnected;
  1436. if (!drm_kms_helper_is_poll_worker()) {
  1437. r = pm_runtime_get_sync(connector->dev->dev);
  1438. if (r < 0)
  1439. return connector_status_disconnected;
  1440. }
  1441. if (!force && radeon_check_hpd_status_unchanged(connector)) {
  1442. ret = connector->status;
  1443. goto out;
  1444. }
  1445. radeon_connector_free_edid(connector);
  1446. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1447. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1448. if (encoder) {
  1449. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1450. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  1451. /* check if panel is valid */
  1452. if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
  1453. ret = connector_status_connected;
  1454. /* don't fetch the edid from the vbios if ddc fails and runpm is
  1455. * enabled so we report disconnected.
  1456. */
  1457. if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
  1458. ret = connector_status_disconnected;
  1459. }
  1460. /* eDP is always DP */
  1461. radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1462. if (!radeon_dig_connector->edp_on)
  1463. atombios_set_edp_panel_power(connector,
  1464. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1465. if (radeon_dp_getdpcd(radeon_connector))
  1466. ret = connector_status_connected;
  1467. if (!radeon_dig_connector->edp_on)
  1468. atombios_set_edp_panel_power(connector,
  1469. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1470. } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
  1471. ENCODER_OBJECT_ID_NONE) {
  1472. /* DP bridges are always DP */
  1473. radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
  1474. /* get the DPCD from the bridge */
  1475. radeon_dp_getdpcd(radeon_connector);
  1476. if (encoder) {
  1477. /* setup ddc on the bridge */
  1478. radeon_atom_ext_encoder_setup_ddc(encoder);
  1479. /* bridge chips are always aux */
  1480. if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
  1481. ret = connector_status_connected;
  1482. else if (radeon_connector->dac_load_detect) { /* try load detection */
  1483. const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1484. ret = encoder_funcs->detect(encoder, connector);
  1485. }
  1486. }
  1487. } else {
  1488. radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
  1489. if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
  1490. ret = connector_status_connected;
  1491. if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
  1492. radeon_dp_getdpcd(radeon_connector);
  1493. r = radeon_dp_mst_probe(radeon_connector);
  1494. if (r == 1)
  1495. ret = connector_status_disconnected;
  1496. }
  1497. } else {
  1498. if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
  1499. if (radeon_dp_getdpcd(radeon_connector)) {
  1500. r = radeon_dp_mst_probe(radeon_connector);
  1501. if (r == 1)
  1502. ret = connector_status_disconnected;
  1503. else
  1504. ret = connector_status_connected;
  1505. }
  1506. } else {
  1507. /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
  1508. if (radeon_ddc_probe(radeon_connector, false))
  1509. ret = connector_status_connected;
  1510. }
  1511. }
  1512. }
  1513. radeon_connector_update_scratch_regs(connector, ret);
  1514. if ((radeon_audio != 0) && encoder) {
  1515. radeon_connector_get_edid(connector);
  1516. radeon_audio_detect(connector, encoder, ret);
  1517. }
  1518. out:
  1519. if (!drm_kms_helper_is_poll_worker()) {
  1520. pm_runtime_mark_last_busy(connector->dev->dev);
  1521. pm_runtime_put_autosuspend(connector->dev->dev);
  1522. }
  1523. return ret;
  1524. }
  1525. static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
  1526. struct drm_display_mode *mode)
  1527. {
  1528. struct drm_device *dev = connector->dev;
  1529. struct radeon_device *rdev = dev->dev_private;
  1530. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1531. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  1532. /* XXX check mode bandwidth */
  1533. if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
  1534. (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
  1535. struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  1536. if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
  1537. return MODE_PANEL;
  1538. if (encoder) {
  1539. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1540. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  1541. /* AVIVO hardware supports downscaling modes larger than the panel
  1542. * to the panel size, but I'm not sure this is desirable.
  1543. */
  1544. if ((mode->hdisplay > native_mode->hdisplay) ||
  1545. (mode->vdisplay > native_mode->vdisplay))
  1546. return MODE_PANEL;
  1547. /* if scaling is disabled, block non-native modes */
  1548. if (radeon_encoder->rmx_type == RMX_OFF) {
  1549. if ((mode->hdisplay != native_mode->hdisplay) ||
  1550. (mode->vdisplay != native_mode->vdisplay))
  1551. return MODE_PANEL;
  1552. }
  1553. }
  1554. } else {
  1555. if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  1556. (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
  1557. return radeon_dp_mode_valid_helper(connector, mode);
  1558. } else {
  1559. if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  1560. /* HDMI 1.3+ supports max clock of 340 Mhz */
  1561. if (mode->clock > 340000)
  1562. return MODE_CLOCK_HIGH;
  1563. } else {
  1564. if (mode->clock > 165000)
  1565. return MODE_CLOCK_HIGH;
  1566. }
  1567. }
  1568. }
  1569. return MODE_OK;
  1570. }
  1571. static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
  1572. .get_modes = radeon_dp_get_modes,
  1573. .mode_valid = radeon_dp_mode_valid,
  1574. .best_encoder = radeon_dvi_encoder,
  1575. };
  1576. static const struct drm_connector_funcs radeon_dp_connector_funcs = {
  1577. .dpms = drm_helper_connector_dpms,
  1578. .detect = radeon_dp_detect,
  1579. .fill_modes = drm_helper_probe_single_connector_modes,
  1580. .set_property = radeon_connector_set_property,
  1581. .destroy = radeon_connector_destroy,
  1582. .force = radeon_dvi_force,
  1583. };
  1584. static const struct drm_connector_funcs radeon_edp_connector_funcs = {
  1585. .dpms = drm_helper_connector_dpms,
  1586. .detect = radeon_dp_detect,
  1587. .fill_modes = drm_helper_probe_single_connector_modes,
  1588. .set_property = radeon_lvds_set_property,
  1589. .destroy = radeon_connector_destroy,
  1590. .force = radeon_dvi_force,
  1591. };
  1592. static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
  1593. .dpms = drm_helper_connector_dpms,
  1594. .detect = radeon_dp_detect,
  1595. .fill_modes = drm_helper_probe_single_connector_modes,
  1596. .set_property = radeon_lvds_set_property,
  1597. .destroy = radeon_connector_destroy,
  1598. .force = radeon_dvi_force,
  1599. };
  1600. void
  1601. radeon_add_atom_connector(struct drm_device *dev,
  1602. uint32_t connector_id,
  1603. uint32_t supported_device,
  1604. int connector_type,
  1605. struct radeon_i2c_bus_rec *i2c_bus,
  1606. uint32_t igp_lane_info,
  1607. uint16_t connector_object_id,
  1608. struct radeon_hpd *hpd,
  1609. struct radeon_router *router)
  1610. {
  1611. struct radeon_device *rdev = dev->dev_private;
  1612. struct drm_connector *connector;
  1613. struct radeon_connector *radeon_connector;
  1614. struct radeon_connector_atom_dig *radeon_dig_connector;
  1615. struct drm_encoder *encoder;
  1616. struct radeon_encoder *radeon_encoder;
  1617. uint32_t subpixel_order = SubPixelNone;
  1618. bool shared_ddc = false;
  1619. bool is_dp_bridge = false;
  1620. bool has_aux = false;
  1621. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  1622. return;
  1623. /* if the user selected tv=0 don't try and add the connector */
  1624. if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
  1625. (connector_type == DRM_MODE_CONNECTOR_Composite) ||
  1626. (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
  1627. (radeon_tv == 0))
  1628. return;
  1629. /* see if we already added it */
  1630. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1631. radeon_connector = to_radeon_connector(connector);
  1632. if (radeon_connector->connector_id == connector_id) {
  1633. radeon_connector->devices |= supported_device;
  1634. return;
  1635. }
  1636. if (radeon_connector->ddc_bus && i2c_bus->valid) {
  1637. if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
  1638. radeon_connector->shared_ddc = true;
  1639. shared_ddc = true;
  1640. }
  1641. if (radeon_connector->router_bus && router->ddc_valid &&
  1642. (radeon_connector->router.router_id == router->router_id)) {
  1643. radeon_connector->shared_ddc = false;
  1644. shared_ddc = false;
  1645. }
  1646. }
  1647. }
  1648. /* check if it's a dp bridge */
  1649. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1650. radeon_encoder = to_radeon_encoder(encoder);
  1651. if (radeon_encoder->devices & supported_device) {
  1652. switch (radeon_encoder->encoder_id) {
  1653. case ENCODER_OBJECT_ID_TRAVIS:
  1654. case ENCODER_OBJECT_ID_NUTMEG:
  1655. is_dp_bridge = true;
  1656. break;
  1657. default:
  1658. break;
  1659. }
  1660. }
  1661. }
  1662. radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
  1663. if (!radeon_connector)
  1664. return;
  1665. connector = &radeon_connector->base;
  1666. radeon_connector->connector_id = connector_id;
  1667. radeon_connector->devices = supported_device;
  1668. radeon_connector->shared_ddc = shared_ddc;
  1669. radeon_connector->connector_object_id = connector_object_id;
  1670. radeon_connector->hpd = *hpd;
  1671. radeon_connector->router = *router;
  1672. if (router->ddc_valid || router->cd_valid) {
  1673. radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
  1674. if (!radeon_connector->router_bus)
  1675. DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
  1676. }
  1677. if (is_dp_bridge) {
  1678. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  1679. if (!radeon_dig_connector)
  1680. goto failed;
  1681. radeon_dig_connector->igp_lane_info = igp_lane_info;
  1682. radeon_connector->con_priv = radeon_dig_connector;
  1683. if (i2c_bus->valid) {
  1684. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1685. if (radeon_connector->ddc_bus)
  1686. has_aux = true;
  1687. else
  1688. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1689. }
  1690. switch (connector_type) {
  1691. case DRM_MODE_CONNECTOR_VGA:
  1692. case DRM_MODE_CONNECTOR_DVIA:
  1693. default:
  1694. drm_connector_init(dev, &radeon_connector->base,
  1695. &radeon_dp_connector_funcs, connector_type);
  1696. drm_connector_helper_add(&radeon_connector->base,
  1697. &radeon_dp_connector_helper_funcs);
  1698. connector->interlace_allowed = true;
  1699. connector->doublescan_allowed = true;
  1700. radeon_connector->dac_load_detect = true;
  1701. drm_object_attach_property(&radeon_connector->base.base,
  1702. rdev->mode_info.load_detect_property,
  1703. 1);
  1704. drm_object_attach_property(&radeon_connector->base.base,
  1705. dev->mode_config.scaling_mode_property,
  1706. DRM_MODE_SCALE_NONE);
  1707. if (ASIC_IS_DCE5(rdev))
  1708. drm_object_attach_property(&radeon_connector->base.base,
  1709. rdev->mode_info.output_csc_property,
  1710. RADEON_OUTPUT_CSC_BYPASS);
  1711. break;
  1712. case DRM_MODE_CONNECTOR_DVII:
  1713. case DRM_MODE_CONNECTOR_DVID:
  1714. case DRM_MODE_CONNECTOR_HDMIA:
  1715. case DRM_MODE_CONNECTOR_HDMIB:
  1716. case DRM_MODE_CONNECTOR_DisplayPort:
  1717. drm_connector_init(dev, &radeon_connector->base,
  1718. &radeon_dp_connector_funcs, connector_type);
  1719. drm_connector_helper_add(&radeon_connector->base,
  1720. &radeon_dp_connector_helper_funcs);
  1721. drm_object_attach_property(&radeon_connector->base.base,
  1722. rdev->mode_info.underscan_property,
  1723. UNDERSCAN_OFF);
  1724. drm_object_attach_property(&radeon_connector->base.base,
  1725. rdev->mode_info.underscan_hborder_property,
  1726. 0);
  1727. drm_object_attach_property(&radeon_connector->base.base,
  1728. rdev->mode_info.underscan_vborder_property,
  1729. 0);
  1730. drm_object_attach_property(&radeon_connector->base.base,
  1731. dev->mode_config.scaling_mode_property,
  1732. DRM_MODE_SCALE_NONE);
  1733. drm_object_attach_property(&radeon_connector->base.base,
  1734. rdev->mode_info.dither_property,
  1735. RADEON_FMT_DITHER_DISABLE);
  1736. if (radeon_audio != 0) {
  1737. drm_object_attach_property(&radeon_connector->base.base,
  1738. rdev->mode_info.audio_property,
  1739. RADEON_AUDIO_AUTO);
  1740. radeon_connector->audio = RADEON_AUDIO_AUTO;
  1741. }
  1742. if (ASIC_IS_DCE5(rdev))
  1743. drm_object_attach_property(&radeon_connector->base.base,
  1744. rdev->mode_info.output_csc_property,
  1745. RADEON_OUTPUT_CSC_BYPASS);
  1746. subpixel_order = SubPixelHorizontalRGB;
  1747. connector->interlace_allowed = true;
  1748. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1749. connector->doublescan_allowed = true;
  1750. else
  1751. connector->doublescan_allowed = false;
  1752. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1753. radeon_connector->dac_load_detect = true;
  1754. drm_object_attach_property(&radeon_connector->base.base,
  1755. rdev->mode_info.load_detect_property,
  1756. 1);
  1757. }
  1758. break;
  1759. case DRM_MODE_CONNECTOR_LVDS:
  1760. case DRM_MODE_CONNECTOR_eDP:
  1761. drm_connector_init(dev, &radeon_connector->base,
  1762. &radeon_lvds_bridge_connector_funcs, connector_type);
  1763. drm_connector_helper_add(&radeon_connector->base,
  1764. &radeon_dp_connector_helper_funcs);
  1765. drm_object_attach_property(&radeon_connector->base.base,
  1766. dev->mode_config.scaling_mode_property,
  1767. DRM_MODE_SCALE_FULLSCREEN);
  1768. subpixel_order = SubPixelHorizontalRGB;
  1769. connector->interlace_allowed = false;
  1770. connector->doublescan_allowed = false;
  1771. break;
  1772. }
  1773. } else {
  1774. switch (connector_type) {
  1775. case DRM_MODE_CONNECTOR_VGA:
  1776. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  1777. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  1778. if (i2c_bus->valid) {
  1779. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1780. if (!radeon_connector->ddc_bus)
  1781. DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1782. }
  1783. radeon_connector->dac_load_detect = true;
  1784. drm_object_attach_property(&radeon_connector->base.base,
  1785. rdev->mode_info.load_detect_property,
  1786. 1);
  1787. if (ASIC_IS_AVIVO(rdev))
  1788. drm_object_attach_property(&radeon_connector->base.base,
  1789. dev->mode_config.scaling_mode_property,
  1790. DRM_MODE_SCALE_NONE);
  1791. if (ASIC_IS_DCE5(rdev))
  1792. drm_object_attach_property(&radeon_connector->base.base,
  1793. rdev->mode_info.output_csc_property,
  1794. RADEON_OUTPUT_CSC_BYPASS);
  1795. /* no HPD on analog connectors */
  1796. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  1797. connector->interlace_allowed = true;
  1798. connector->doublescan_allowed = true;
  1799. break;
  1800. case DRM_MODE_CONNECTOR_DVIA:
  1801. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  1802. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  1803. if (i2c_bus->valid) {
  1804. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1805. if (!radeon_connector->ddc_bus)
  1806. DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1807. }
  1808. radeon_connector->dac_load_detect = true;
  1809. drm_object_attach_property(&radeon_connector->base.base,
  1810. rdev->mode_info.load_detect_property,
  1811. 1);
  1812. if (ASIC_IS_AVIVO(rdev))
  1813. drm_object_attach_property(&radeon_connector->base.base,
  1814. dev->mode_config.scaling_mode_property,
  1815. DRM_MODE_SCALE_NONE);
  1816. if (ASIC_IS_DCE5(rdev))
  1817. drm_object_attach_property(&radeon_connector->base.base,
  1818. rdev->mode_info.output_csc_property,
  1819. RADEON_OUTPUT_CSC_BYPASS);
  1820. /* no HPD on analog connectors */
  1821. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  1822. connector->interlace_allowed = true;
  1823. connector->doublescan_allowed = true;
  1824. break;
  1825. case DRM_MODE_CONNECTOR_DVII:
  1826. case DRM_MODE_CONNECTOR_DVID:
  1827. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  1828. if (!radeon_dig_connector)
  1829. goto failed;
  1830. radeon_dig_connector->igp_lane_info = igp_lane_info;
  1831. radeon_connector->con_priv = radeon_dig_connector;
  1832. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  1833. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  1834. if (i2c_bus->valid) {
  1835. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1836. if (!radeon_connector->ddc_bus)
  1837. DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1838. }
  1839. subpixel_order = SubPixelHorizontalRGB;
  1840. drm_object_attach_property(&radeon_connector->base.base,
  1841. rdev->mode_info.coherent_mode_property,
  1842. 1);
  1843. if (ASIC_IS_AVIVO(rdev)) {
  1844. drm_object_attach_property(&radeon_connector->base.base,
  1845. rdev->mode_info.underscan_property,
  1846. UNDERSCAN_OFF);
  1847. drm_object_attach_property(&radeon_connector->base.base,
  1848. rdev->mode_info.underscan_hborder_property,
  1849. 0);
  1850. drm_object_attach_property(&radeon_connector->base.base,
  1851. rdev->mode_info.underscan_vborder_property,
  1852. 0);
  1853. drm_object_attach_property(&radeon_connector->base.base,
  1854. rdev->mode_info.dither_property,
  1855. RADEON_FMT_DITHER_DISABLE);
  1856. drm_object_attach_property(&radeon_connector->base.base,
  1857. dev->mode_config.scaling_mode_property,
  1858. DRM_MODE_SCALE_NONE);
  1859. }
  1860. if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
  1861. drm_object_attach_property(&radeon_connector->base.base,
  1862. rdev->mode_info.audio_property,
  1863. RADEON_AUDIO_AUTO);
  1864. radeon_connector->audio = RADEON_AUDIO_AUTO;
  1865. }
  1866. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  1867. radeon_connector->dac_load_detect = true;
  1868. drm_object_attach_property(&radeon_connector->base.base,
  1869. rdev->mode_info.load_detect_property,
  1870. 1);
  1871. }
  1872. if (ASIC_IS_DCE5(rdev))
  1873. drm_object_attach_property(&radeon_connector->base.base,
  1874. rdev->mode_info.output_csc_property,
  1875. RADEON_OUTPUT_CSC_BYPASS);
  1876. connector->interlace_allowed = true;
  1877. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  1878. connector->doublescan_allowed = true;
  1879. else
  1880. connector->doublescan_allowed = false;
  1881. break;
  1882. case DRM_MODE_CONNECTOR_HDMIA:
  1883. case DRM_MODE_CONNECTOR_HDMIB:
  1884. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  1885. if (!radeon_dig_connector)
  1886. goto failed;
  1887. radeon_dig_connector->igp_lane_info = igp_lane_info;
  1888. radeon_connector->con_priv = radeon_dig_connector;
  1889. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  1890. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  1891. if (i2c_bus->valid) {
  1892. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1893. if (!radeon_connector->ddc_bus)
  1894. DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1895. }
  1896. drm_object_attach_property(&radeon_connector->base.base,
  1897. rdev->mode_info.coherent_mode_property,
  1898. 1);
  1899. if (ASIC_IS_AVIVO(rdev)) {
  1900. drm_object_attach_property(&radeon_connector->base.base,
  1901. rdev->mode_info.underscan_property,
  1902. UNDERSCAN_OFF);
  1903. drm_object_attach_property(&radeon_connector->base.base,
  1904. rdev->mode_info.underscan_hborder_property,
  1905. 0);
  1906. drm_object_attach_property(&radeon_connector->base.base,
  1907. rdev->mode_info.underscan_vborder_property,
  1908. 0);
  1909. drm_object_attach_property(&radeon_connector->base.base,
  1910. rdev->mode_info.dither_property,
  1911. RADEON_FMT_DITHER_DISABLE);
  1912. drm_object_attach_property(&radeon_connector->base.base,
  1913. dev->mode_config.scaling_mode_property,
  1914. DRM_MODE_SCALE_NONE);
  1915. }
  1916. if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
  1917. drm_object_attach_property(&radeon_connector->base.base,
  1918. rdev->mode_info.audio_property,
  1919. RADEON_AUDIO_AUTO);
  1920. radeon_connector->audio = RADEON_AUDIO_AUTO;
  1921. }
  1922. if (ASIC_IS_DCE5(rdev))
  1923. drm_object_attach_property(&radeon_connector->base.base,
  1924. rdev->mode_info.output_csc_property,
  1925. RADEON_OUTPUT_CSC_BYPASS);
  1926. subpixel_order = SubPixelHorizontalRGB;
  1927. connector->interlace_allowed = true;
  1928. if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
  1929. connector->doublescan_allowed = true;
  1930. else
  1931. connector->doublescan_allowed = false;
  1932. break;
  1933. case DRM_MODE_CONNECTOR_DisplayPort:
  1934. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  1935. if (!radeon_dig_connector)
  1936. goto failed;
  1937. radeon_dig_connector->igp_lane_info = igp_lane_info;
  1938. radeon_connector->con_priv = radeon_dig_connector;
  1939. drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
  1940. drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
  1941. if (i2c_bus->valid) {
  1942. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1943. if (radeon_connector->ddc_bus)
  1944. has_aux = true;
  1945. else
  1946. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1947. }
  1948. subpixel_order = SubPixelHorizontalRGB;
  1949. drm_object_attach_property(&radeon_connector->base.base,
  1950. rdev->mode_info.coherent_mode_property,
  1951. 1);
  1952. if (ASIC_IS_AVIVO(rdev)) {
  1953. drm_object_attach_property(&radeon_connector->base.base,
  1954. rdev->mode_info.underscan_property,
  1955. UNDERSCAN_OFF);
  1956. drm_object_attach_property(&radeon_connector->base.base,
  1957. rdev->mode_info.underscan_hborder_property,
  1958. 0);
  1959. drm_object_attach_property(&radeon_connector->base.base,
  1960. rdev->mode_info.underscan_vborder_property,
  1961. 0);
  1962. drm_object_attach_property(&radeon_connector->base.base,
  1963. rdev->mode_info.dither_property,
  1964. RADEON_FMT_DITHER_DISABLE);
  1965. drm_object_attach_property(&radeon_connector->base.base,
  1966. dev->mode_config.scaling_mode_property,
  1967. DRM_MODE_SCALE_NONE);
  1968. }
  1969. if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
  1970. drm_object_attach_property(&radeon_connector->base.base,
  1971. rdev->mode_info.audio_property,
  1972. RADEON_AUDIO_AUTO);
  1973. radeon_connector->audio = RADEON_AUDIO_AUTO;
  1974. }
  1975. if (ASIC_IS_DCE5(rdev))
  1976. drm_object_attach_property(&radeon_connector->base.base,
  1977. rdev->mode_info.output_csc_property,
  1978. RADEON_OUTPUT_CSC_BYPASS);
  1979. connector->interlace_allowed = true;
  1980. /* in theory with a DP to VGA converter... */
  1981. connector->doublescan_allowed = false;
  1982. break;
  1983. case DRM_MODE_CONNECTOR_eDP:
  1984. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  1985. if (!radeon_dig_connector)
  1986. goto failed;
  1987. radeon_dig_connector->igp_lane_info = igp_lane_info;
  1988. radeon_connector->con_priv = radeon_dig_connector;
  1989. drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
  1990. drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
  1991. if (i2c_bus->valid) {
  1992. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  1993. if (radeon_connector->ddc_bus)
  1994. has_aux = true;
  1995. else
  1996. DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  1997. }
  1998. drm_object_attach_property(&radeon_connector->base.base,
  1999. dev->mode_config.scaling_mode_property,
  2000. DRM_MODE_SCALE_FULLSCREEN);
  2001. subpixel_order = SubPixelHorizontalRGB;
  2002. connector->interlace_allowed = false;
  2003. connector->doublescan_allowed = false;
  2004. break;
  2005. case DRM_MODE_CONNECTOR_SVIDEO:
  2006. case DRM_MODE_CONNECTOR_Composite:
  2007. case DRM_MODE_CONNECTOR_9PinDIN:
  2008. drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
  2009. drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
  2010. radeon_connector->dac_load_detect = true;
  2011. drm_object_attach_property(&radeon_connector->base.base,
  2012. rdev->mode_info.load_detect_property,
  2013. 1);
  2014. drm_object_attach_property(&radeon_connector->base.base,
  2015. rdev->mode_info.tv_std_property,
  2016. radeon_atombios_get_tv_info(rdev));
  2017. /* no HPD on analog connectors */
  2018. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  2019. connector->interlace_allowed = false;
  2020. connector->doublescan_allowed = false;
  2021. break;
  2022. case DRM_MODE_CONNECTOR_LVDS:
  2023. radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
  2024. if (!radeon_dig_connector)
  2025. goto failed;
  2026. radeon_dig_connector->igp_lane_info = igp_lane_info;
  2027. radeon_connector->con_priv = radeon_dig_connector;
  2028. drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
  2029. drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
  2030. if (i2c_bus->valid) {
  2031. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  2032. if (!radeon_connector->ddc_bus)
  2033. DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  2034. }
  2035. drm_object_attach_property(&radeon_connector->base.base,
  2036. dev->mode_config.scaling_mode_property,
  2037. DRM_MODE_SCALE_FULLSCREEN);
  2038. subpixel_order = SubPixelHorizontalRGB;
  2039. connector->interlace_allowed = false;
  2040. connector->doublescan_allowed = false;
  2041. break;
  2042. }
  2043. }
  2044. if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
  2045. if (i2c_bus->valid) {
  2046. connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  2047. DRM_CONNECTOR_POLL_DISCONNECT;
  2048. }
  2049. } else
  2050. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2051. connector->display_info.subpixel_order = subpixel_order;
  2052. drm_connector_register(connector);
  2053. if (has_aux)
  2054. radeon_dp_aux_init(radeon_connector);
  2055. return;
  2056. failed:
  2057. drm_connector_cleanup(connector);
  2058. kfree(connector);
  2059. }
  2060. void
  2061. radeon_add_legacy_connector(struct drm_device *dev,
  2062. uint32_t connector_id,
  2063. uint32_t supported_device,
  2064. int connector_type,
  2065. struct radeon_i2c_bus_rec *i2c_bus,
  2066. uint16_t connector_object_id,
  2067. struct radeon_hpd *hpd)
  2068. {
  2069. struct radeon_device *rdev = dev->dev_private;
  2070. struct drm_connector *connector;
  2071. struct radeon_connector *radeon_connector;
  2072. uint32_t subpixel_order = SubPixelNone;
  2073. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  2074. return;
  2075. /* if the user selected tv=0 don't try and add the connector */
  2076. if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
  2077. (connector_type == DRM_MODE_CONNECTOR_Composite) ||
  2078. (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
  2079. (radeon_tv == 0))
  2080. return;
  2081. /* see if we already added it */
  2082. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2083. radeon_connector = to_radeon_connector(connector);
  2084. if (radeon_connector->connector_id == connector_id) {
  2085. radeon_connector->devices |= supported_device;
  2086. return;
  2087. }
  2088. }
  2089. radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
  2090. if (!radeon_connector)
  2091. return;
  2092. connector = &radeon_connector->base;
  2093. radeon_connector->connector_id = connector_id;
  2094. radeon_connector->devices = supported_device;
  2095. radeon_connector->connector_object_id = connector_object_id;
  2096. radeon_connector->hpd = *hpd;
  2097. switch (connector_type) {
  2098. case DRM_MODE_CONNECTOR_VGA:
  2099. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  2100. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  2101. if (i2c_bus->valid) {
  2102. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  2103. if (!radeon_connector->ddc_bus)
  2104. DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  2105. }
  2106. radeon_connector->dac_load_detect = true;
  2107. drm_object_attach_property(&radeon_connector->base.base,
  2108. rdev->mode_info.load_detect_property,
  2109. 1);
  2110. /* no HPD on analog connectors */
  2111. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  2112. connector->interlace_allowed = true;
  2113. connector->doublescan_allowed = true;
  2114. break;
  2115. case DRM_MODE_CONNECTOR_DVIA:
  2116. drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
  2117. drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
  2118. if (i2c_bus->valid) {
  2119. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  2120. if (!radeon_connector->ddc_bus)
  2121. DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  2122. }
  2123. radeon_connector->dac_load_detect = true;
  2124. drm_object_attach_property(&radeon_connector->base.base,
  2125. rdev->mode_info.load_detect_property,
  2126. 1);
  2127. /* no HPD on analog connectors */
  2128. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  2129. connector->interlace_allowed = true;
  2130. connector->doublescan_allowed = true;
  2131. break;
  2132. case DRM_MODE_CONNECTOR_DVII:
  2133. case DRM_MODE_CONNECTOR_DVID:
  2134. drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
  2135. drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
  2136. if (i2c_bus->valid) {
  2137. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  2138. if (!radeon_connector->ddc_bus)
  2139. DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  2140. }
  2141. if (connector_type == DRM_MODE_CONNECTOR_DVII) {
  2142. radeon_connector->dac_load_detect = true;
  2143. drm_object_attach_property(&radeon_connector->base.base,
  2144. rdev->mode_info.load_detect_property,
  2145. 1);
  2146. }
  2147. subpixel_order = SubPixelHorizontalRGB;
  2148. connector->interlace_allowed = true;
  2149. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  2150. connector->doublescan_allowed = true;
  2151. else
  2152. connector->doublescan_allowed = false;
  2153. break;
  2154. case DRM_MODE_CONNECTOR_SVIDEO:
  2155. case DRM_MODE_CONNECTOR_Composite:
  2156. case DRM_MODE_CONNECTOR_9PinDIN:
  2157. drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
  2158. drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
  2159. radeon_connector->dac_load_detect = true;
  2160. /* RS400,RC410,RS480 chipset seems to report a lot
  2161. * of false positive on load detect, we haven't yet
  2162. * found a way to make load detect reliable on those
  2163. * chipset, thus just disable it for TV.
  2164. */
  2165. if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
  2166. radeon_connector->dac_load_detect = false;
  2167. drm_object_attach_property(&radeon_connector->base.base,
  2168. rdev->mode_info.load_detect_property,
  2169. radeon_connector->dac_load_detect);
  2170. drm_object_attach_property(&radeon_connector->base.base,
  2171. rdev->mode_info.tv_std_property,
  2172. radeon_combios_get_tv_info(rdev));
  2173. /* no HPD on analog connectors */
  2174. radeon_connector->hpd.hpd = RADEON_HPD_NONE;
  2175. connector->interlace_allowed = false;
  2176. connector->doublescan_allowed = false;
  2177. break;
  2178. case DRM_MODE_CONNECTOR_LVDS:
  2179. drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
  2180. drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
  2181. if (i2c_bus->valid) {
  2182. radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
  2183. if (!radeon_connector->ddc_bus)
  2184. DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
  2185. }
  2186. drm_object_attach_property(&radeon_connector->base.base,
  2187. dev->mode_config.scaling_mode_property,
  2188. DRM_MODE_SCALE_FULLSCREEN);
  2189. subpixel_order = SubPixelHorizontalRGB;
  2190. connector->interlace_allowed = false;
  2191. connector->doublescan_allowed = false;
  2192. break;
  2193. }
  2194. if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
  2195. if (i2c_bus->valid) {
  2196. connector->polled = DRM_CONNECTOR_POLL_CONNECT |
  2197. DRM_CONNECTOR_POLL_DISCONNECT;
  2198. }
  2199. } else
  2200. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2201. connector->display_info.subpixel_order = subpixel_order;
  2202. drm_connector_register(connector);
  2203. }
  2204. void radeon_setup_mst_connector(struct drm_device *dev)
  2205. {
  2206. struct radeon_device *rdev = dev->dev_private;
  2207. struct drm_connector *connector;
  2208. struct radeon_connector *radeon_connector;
  2209. if (!ASIC_IS_DCE5(rdev))
  2210. return;
  2211. if (radeon_mst == 0)
  2212. return;
  2213. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2214. int ret;
  2215. radeon_connector = to_radeon_connector(connector);
  2216. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  2217. continue;
  2218. ret = radeon_dp_mst_init(radeon_connector);
  2219. }
  2220. }