atombios_encoders.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  1. /*
  2. * Copyright 2007-11 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 "drmP.h"
  27. #include "drm_crtc_helper.h"
  28. #include "radeon_drm.h"
  29. #include "radeon.h"
  30. #include "atom.h"
  31. extern int atom_debug;
  32. /* evil but including atombios.h is much worse */
  33. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  34. struct drm_display_mode *mode);
  35. static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
  36. {
  37. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  38. switch (radeon_encoder->encoder_id) {
  39. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  40. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  41. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  42. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  43. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  44. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  45. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  46. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  47. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  48. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  49. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  50. return true;
  51. default:
  52. return false;
  53. }
  54. }
  55. static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
  56. struct drm_display_mode *mode,
  57. struct drm_display_mode *adjusted_mode)
  58. {
  59. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  60. struct drm_device *dev = encoder->dev;
  61. struct radeon_device *rdev = dev->dev_private;
  62. /* set the active encoder to connector routing */
  63. radeon_encoder_set_active_device(encoder);
  64. drm_mode_set_crtcinfo(adjusted_mode, 0);
  65. /* hw bug */
  66. if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
  67. && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
  68. adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
  69. /* get the native mode for LVDS */
  70. if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT))
  71. radeon_panel_mode_fixup(encoder, adjusted_mode);
  72. /* get the native mode for TV */
  73. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
  74. struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
  75. if (tv_dac) {
  76. if (tv_dac->tv_std == TV_STD_NTSC ||
  77. tv_dac->tv_std == TV_STD_NTSC_J ||
  78. tv_dac->tv_std == TV_STD_PAL_M)
  79. radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
  80. else
  81. radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
  82. }
  83. }
  84. if (ASIC_IS_DCE3(rdev) &&
  85. ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  86. (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE))) {
  87. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  88. radeon_dp_set_link_config(connector, adjusted_mode);
  89. }
  90. return true;
  91. }
  92. static void
  93. atombios_dac_setup(struct drm_encoder *encoder, int action)
  94. {
  95. struct drm_device *dev = encoder->dev;
  96. struct radeon_device *rdev = dev->dev_private;
  97. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  98. DAC_ENCODER_CONTROL_PS_ALLOCATION args;
  99. int index = 0;
  100. struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
  101. memset(&args, 0, sizeof(args));
  102. switch (radeon_encoder->encoder_id) {
  103. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  104. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  105. index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl);
  106. break;
  107. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  108. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  109. index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl);
  110. break;
  111. }
  112. args.ucAction = action;
  113. if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT))
  114. args.ucDacStandard = ATOM_DAC1_PS2;
  115. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  116. args.ucDacStandard = ATOM_DAC1_CV;
  117. else {
  118. switch (dac_info->tv_std) {
  119. case TV_STD_PAL:
  120. case TV_STD_PAL_M:
  121. case TV_STD_SCART_PAL:
  122. case TV_STD_SECAM:
  123. case TV_STD_PAL_CN:
  124. args.ucDacStandard = ATOM_DAC1_PAL;
  125. break;
  126. case TV_STD_NTSC:
  127. case TV_STD_NTSC_J:
  128. case TV_STD_PAL_60:
  129. default:
  130. args.ucDacStandard = ATOM_DAC1_NTSC;
  131. break;
  132. }
  133. }
  134. args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  135. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  136. }
  137. static void
  138. atombios_tv_setup(struct drm_encoder *encoder, int action)
  139. {
  140. struct drm_device *dev = encoder->dev;
  141. struct radeon_device *rdev = dev->dev_private;
  142. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  143. TV_ENCODER_CONTROL_PS_ALLOCATION args;
  144. int index = 0;
  145. struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
  146. memset(&args, 0, sizeof(args));
  147. index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
  148. args.sTVEncoder.ucAction = action;
  149. if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  150. args.sTVEncoder.ucTvStandard = ATOM_TV_CV;
  151. else {
  152. switch (dac_info->tv_std) {
  153. case TV_STD_NTSC:
  154. args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
  155. break;
  156. case TV_STD_PAL:
  157. args.sTVEncoder.ucTvStandard = ATOM_TV_PAL;
  158. break;
  159. case TV_STD_PAL_M:
  160. args.sTVEncoder.ucTvStandard = ATOM_TV_PALM;
  161. break;
  162. case TV_STD_PAL_60:
  163. args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60;
  164. break;
  165. case TV_STD_NTSC_J:
  166. args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ;
  167. break;
  168. case TV_STD_SCART_PAL:
  169. args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */
  170. break;
  171. case TV_STD_SECAM:
  172. args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM;
  173. break;
  174. case TV_STD_PAL_CN:
  175. args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN;
  176. break;
  177. default:
  178. args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
  179. break;
  180. }
  181. }
  182. args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  183. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  184. }
  185. union dvo_encoder_control {
  186. ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
  187. DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
  188. DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
  189. };
  190. void
  191. atombios_dvo_setup(struct drm_encoder *encoder, int action)
  192. {
  193. struct drm_device *dev = encoder->dev;
  194. struct radeon_device *rdev = dev->dev_private;
  195. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  196. union dvo_encoder_control args;
  197. int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
  198. uint8_t frev, crev;
  199. memset(&args, 0, sizeof(args));
  200. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  201. return;
  202. /* some R4xx chips have the wrong frev */
  203. if (rdev->family <= CHIP_RV410)
  204. frev = 1;
  205. switch (frev) {
  206. case 1:
  207. switch (crev) {
  208. case 1:
  209. /* R4xx, R5xx */
  210. args.ext_tmds.sXTmdsEncoder.ucEnable = action;
  211. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  212. args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
  213. args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
  214. break;
  215. case 2:
  216. /* RS600/690/740 */
  217. args.dvo.sDVOEncoder.ucAction = action;
  218. args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  219. /* DFP1, CRT1, TV1 depending on the type of port */
  220. args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
  221. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  222. args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
  223. break;
  224. case 3:
  225. /* R6xx */
  226. args.dvo_v3.ucAction = action;
  227. args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  228. args.dvo_v3.ucDVOConfig = 0; /* XXX */
  229. break;
  230. default:
  231. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  232. break;
  233. }
  234. break;
  235. default:
  236. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  237. break;
  238. }
  239. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  240. }
  241. union lvds_encoder_control {
  242. LVDS_ENCODER_CONTROL_PS_ALLOCATION v1;
  243. LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
  244. };
  245. void
  246. atombios_digital_setup(struct drm_encoder *encoder, int action)
  247. {
  248. struct drm_device *dev = encoder->dev;
  249. struct radeon_device *rdev = dev->dev_private;
  250. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  251. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  252. union lvds_encoder_control args;
  253. int index = 0;
  254. int hdmi_detected = 0;
  255. uint8_t frev, crev;
  256. if (!dig)
  257. return;
  258. if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  259. hdmi_detected = 1;
  260. memset(&args, 0, sizeof(args));
  261. switch (radeon_encoder->encoder_id) {
  262. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  263. index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
  264. break;
  265. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  266. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  267. index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl);
  268. break;
  269. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  270. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  271. index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
  272. else
  273. index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl);
  274. break;
  275. }
  276. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  277. return;
  278. switch (frev) {
  279. case 1:
  280. case 2:
  281. switch (crev) {
  282. case 1:
  283. args.v1.ucMisc = 0;
  284. args.v1.ucAction = action;
  285. if (hdmi_detected)
  286. args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
  287. args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  288. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  289. if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
  290. args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
  291. if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
  292. args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
  293. } else {
  294. if (dig->linkb)
  295. args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
  296. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  297. args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
  298. /*if (pScrn->rgbBits == 8) */
  299. args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
  300. }
  301. break;
  302. case 2:
  303. case 3:
  304. args.v2.ucMisc = 0;
  305. args.v2.ucAction = action;
  306. if (crev == 3) {
  307. if (dig->coherent_mode)
  308. args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
  309. }
  310. if (hdmi_detected)
  311. args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
  312. args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  313. args.v2.ucTruncate = 0;
  314. args.v2.ucSpatial = 0;
  315. args.v2.ucTemporal = 0;
  316. args.v2.ucFRC = 0;
  317. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  318. if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
  319. args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
  320. if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) {
  321. args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN;
  322. if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
  323. args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH;
  324. }
  325. if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) {
  326. args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN;
  327. if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
  328. args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH;
  329. if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2)
  330. args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4;
  331. }
  332. } else {
  333. if (dig->linkb)
  334. args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
  335. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  336. args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
  337. }
  338. break;
  339. default:
  340. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  341. break;
  342. }
  343. break;
  344. default:
  345. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  346. break;
  347. }
  348. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  349. }
  350. int
  351. atombios_get_encoder_mode(struct drm_encoder *encoder)
  352. {
  353. struct drm_device *dev = encoder->dev;
  354. struct radeon_device *rdev = dev->dev_private;
  355. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  356. struct drm_connector *connector;
  357. struct radeon_connector *radeon_connector;
  358. struct radeon_connector_atom_dig *dig_connector;
  359. /* dp bridges are always DP */
  360. if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)
  361. return ATOM_ENCODER_MODE_DP;
  362. /* DVO is always DVO */
  363. if (radeon_encoder->encoder_id == ATOM_ENCODER_MODE_DVO)
  364. return ATOM_ENCODER_MODE_DVO;
  365. connector = radeon_get_connector_for_encoder(encoder);
  366. /* if we don't have an active device yet, just use one of
  367. * the connectors tied to the encoder.
  368. */
  369. if (!connector)
  370. connector = radeon_get_connector_for_encoder_init(encoder);
  371. radeon_connector = to_radeon_connector(connector);
  372. switch (connector->connector_type) {
  373. case DRM_MODE_CONNECTOR_DVII:
  374. case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
  375. if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
  376. radeon_audio &&
  377. !ASIC_IS_DCE6(rdev)) /* remove once we support DCE6 */
  378. return ATOM_ENCODER_MODE_HDMI;
  379. else if (radeon_connector->use_digital)
  380. return ATOM_ENCODER_MODE_DVI;
  381. else
  382. return ATOM_ENCODER_MODE_CRT;
  383. break;
  384. case DRM_MODE_CONNECTOR_DVID:
  385. case DRM_MODE_CONNECTOR_HDMIA:
  386. default:
  387. if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
  388. radeon_audio &&
  389. !ASIC_IS_DCE6(rdev)) /* remove once we support DCE6 */
  390. return ATOM_ENCODER_MODE_HDMI;
  391. else
  392. return ATOM_ENCODER_MODE_DVI;
  393. break;
  394. case DRM_MODE_CONNECTOR_LVDS:
  395. return ATOM_ENCODER_MODE_LVDS;
  396. break;
  397. case DRM_MODE_CONNECTOR_DisplayPort:
  398. dig_connector = radeon_connector->con_priv;
  399. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  400. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
  401. return ATOM_ENCODER_MODE_DP;
  402. else if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
  403. radeon_audio &&
  404. !ASIC_IS_DCE6(rdev)) /* remove once we support DCE6 */
  405. return ATOM_ENCODER_MODE_HDMI;
  406. else
  407. return ATOM_ENCODER_MODE_DVI;
  408. break;
  409. case DRM_MODE_CONNECTOR_eDP:
  410. return ATOM_ENCODER_MODE_DP;
  411. case DRM_MODE_CONNECTOR_DVIA:
  412. case DRM_MODE_CONNECTOR_VGA:
  413. return ATOM_ENCODER_MODE_CRT;
  414. break;
  415. case DRM_MODE_CONNECTOR_Composite:
  416. case DRM_MODE_CONNECTOR_SVIDEO:
  417. case DRM_MODE_CONNECTOR_9PinDIN:
  418. /* fix me */
  419. return ATOM_ENCODER_MODE_TV;
  420. /*return ATOM_ENCODER_MODE_CV;*/
  421. break;
  422. }
  423. }
  424. /*
  425. * DIG Encoder/Transmitter Setup
  426. *
  427. * DCE 3.0/3.1
  428. * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
  429. * Supports up to 3 digital outputs
  430. * - 2 DIG encoder blocks.
  431. * DIG1 can drive UNIPHY link A or link B
  432. * DIG2 can drive UNIPHY link B or LVTMA
  433. *
  434. * DCE 3.2
  435. * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
  436. * Supports up to 5 digital outputs
  437. * - 2 DIG encoder blocks.
  438. * DIG1/2 can drive UNIPHY0/1/2 link A or link B
  439. *
  440. * DCE 4.0/5.0/6.0
  441. * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
  442. * Supports up to 6 digital outputs
  443. * - 6 DIG encoder blocks.
  444. * - DIG to PHY mapping is hardcoded
  445. * DIG1 drives UNIPHY0 link A, A+B
  446. * DIG2 drives UNIPHY0 link B
  447. * DIG3 drives UNIPHY1 link A, A+B
  448. * DIG4 drives UNIPHY1 link B
  449. * DIG5 drives UNIPHY2 link A, A+B
  450. * DIG6 drives UNIPHY2 link B
  451. *
  452. * DCE 4.1
  453. * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
  454. * Supports up to 6 digital outputs
  455. * - 2 DIG encoder blocks.
  456. * llano
  457. * DIG1/2 can drive UNIPHY0/1/2 link A or link B
  458. * ontario
  459. * DIG1 drives UNIPHY0/1/2 link A
  460. * DIG2 drives UNIPHY0/1/2 link B
  461. *
  462. * Routing
  463. * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
  464. * Examples:
  465. * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
  466. * crtc1 -> dig1 -> UNIPHY0 link B -> DP
  467. * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
  468. * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
  469. */
  470. union dig_encoder_control {
  471. DIG_ENCODER_CONTROL_PS_ALLOCATION v1;
  472. DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
  473. DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
  474. DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
  475. };
  476. void
  477. atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode)
  478. {
  479. struct drm_device *dev = encoder->dev;
  480. struct radeon_device *rdev = dev->dev_private;
  481. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  482. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  483. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  484. union dig_encoder_control args;
  485. int index = 0;
  486. uint8_t frev, crev;
  487. int dp_clock = 0;
  488. int dp_lane_count = 0;
  489. int hpd_id = RADEON_HPD_NONE;
  490. int bpc = 8;
  491. if (connector) {
  492. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  493. struct radeon_connector_atom_dig *dig_connector =
  494. radeon_connector->con_priv;
  495. dp_clock = dig_connector->dp_clock;
  496. dp_lane_count = dig_connector->dp_lane_count;
  497. hpd_id = radeon_connector->hpd.hpd;
  498. /* bpc = connector->display_info.bpc; */
  499. }
  500. /* no dig encoder assigned */
  501. if (dig->dig_encoder == -1)
  502. return;
  503. memset(&args, 0, sizeof(args));
  504. if (ASIC_IS_DCE4(rdev))
  505. index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl);
  506. else {
  507. if (dig->dig_encoder)
  508. index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
  509. else
  510. index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
  511. }
  512. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  513. return;
  514. switch (frev) {
  515. case 1:
  516. switch (crev) {
  517. case 1:
  518. args.v1.ucAction = action;
  519. args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  520. if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
  521. args.v3.ucPanelMode = panel_mode;
  522. else
  523. args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder);
  524. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
  525. args.v1.ucLaneNum = dp_lane_count;
  526. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  527. args.v1.ucLaneNum = 8;
  528. else
  529. args.v1.ucLaneNum = 4;
  530. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
  531. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
  532. switch (radeon_encoder->encoder_id) {
  533. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  534. args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1;
  535. break;
  536. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  537. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  538. args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2;
  539. break;
  540. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  541. args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3;
  542. break;
  543. }
  544. if (dig->linkb)
  545. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
  546. else
  547. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
  548. break;
  549. case 2:
  550. case 3:
  551. args.v3.ucAction = action;
  552. args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  553. if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
  554. args.v3.ucPanelMode = panel_mode;
  555. else
  556. args.v3.ucEncoderMode = atombios_get_encoder_mode(encoder);
  557. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
  558. args.v3.ucLaneNum = dp_lane_count;
  559. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  560. args.v3.ucLaneNum = 8;
  561. else
  562. args.v3.ucLaneNum = 4;
  563. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
  564. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
  565. args.v3.acConfig.ucDigSel = dig->dig_encoder;
  566. switch (bpc) {
  567. case 0:
  568. args.v3.ucBitPerColor = PANEL_BPC_UNDEFINE;
  569. break;
  570. case 6:
  571. args.v3.ucBitPerColor = PANEL_6BIT_PER_COLOR;
  572. break;
  573. case 8:
  574. default:
  575. args.v3.ucBitPerColor = PANEL_8BIT_PER_COLOR;
  576. break;
  577. case 10:
  578. args.v3.ucBitPerColor = PANEL_10BIT_PER_COLOR;
  579. break;
  580. case 12:
  581. args.v3.ucBitPerColor = PANEL_12BIT_PER_COLOR;
  582. break;
  583. case 16:
  584. args.v3.ucBitPerColor = PANEL_16BIT_PER_COLOR;
  585. break;
  586. }
  587. break;
  588. case 4:
  589. args.v4.ucAction = action;
  590. args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  591. if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
  592. args.v4.ucPanelMode = panel_mode;
  593. else
  594. args.v4.ucEncoderMode = atombios_get_encoder_mode(encoder);
  595. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
  596. args.v4.ucLaneNum = dp_lane_count;
  597. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  598. args.v4.ucLaneNum = 8;
  599. else
  600. args.v4.ucLaneNum = 4;
  601. if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode)) {
  602. if (dp_clock == 270000)
  603. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ;
  604. else if (dp_clock == 540000)
  605. args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ;
  606. }
  607. args.v4.acConfig.ucDigSel = dig->dig_encoder;
  608. switch (bpc) {
  609. case 0:
  610. args.v4.ucBitPerColor = PANEL_BPC_UNDEFINE;
  611. break;
  612. case 6:
  613. args.v4.ucBitPerColor = PANEL_6BIT_PER_COLOR;
  614. break;
  615. case 8:
  616. default:
  617. args.v4.ucBitPerColor = PANEL_8BIT_PER_COLOR;
  618. break;
  619. case 10:
  620. args.v4.ucBitPerColor = PANEL_10BIT_PER_COLOR;
  621. break;
  622. case 12:
  623. args.v4.ucBitPerColor = PANEL_12BIT_PER_COLOR;
  624. break;
  625. case 16:
  626. args.v4.ucBitPerColor = PANEL_16BIT_PER_COLOR;
  627. break;
  628. }
  629. if (hpd_id == RADEON_HPD_NONE)
  630. args.v4.ucHPD_ID = 0;
  631. else
  632. args.v4.ucHPD_ID = hpd_id + 1;
  633. break;
  634. default:
  635. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  636. break;
  637. }
  638. break;
  639. default:
  640. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  641. break;
  642. }
  643. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  644. }
  645. union dig_transmitter_control {
  646. DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
  647. DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
  648. DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
  649. DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
  650. DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5;
  651. };
  652. void
  653. atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
  654. {
  655. struct drm_device *dev = encoder->dev;
  656. struct radeon_device *rdev = dev->dev_private;
  657. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  658. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  659. struct drm_connector *connector;
  660. union dig_transmitter_control args;
  661. int index = 0;
  662. uint8_t frev, crev;
  663. bool is_dp = false;
  664. int pll_id = 0;
  665. int dp_clock = 0;
  666. int dp_lane_count = 0;
  667. int connector_object_id = 0;
  668. int igp_lane_info = 0;
  669. int dig_encoder = dig->dig_encoder;
  670. int hpd_id = RADEON_HPD_NONE;
  671. if (action == ATOM_TRANSMITTER_ACTION_INIT) {
  672. connector = radeon_get_connector_for_encoder_init(encoder);
  673. /* just needed to avoid bailing in the encoder check. the encoder
  674. * isn't used for init
  675. */
  676. dig_encoder = 0;
  677. } else
  678. connector = radeon_get_connector_for_encoder(encoder);
  679. if (connector) {
  680. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  681. struct radeon_connector_atom_dig *dig_connector =
  682. radeon_connector->con_priv;
  683. hpd_id = radeon_connector->hpd.hpd;
  684. dp_clock = dig_connector->dp_clock;
  685. dp_lane_count = dig_connector->dp_lane_count;
  686. connector_object_id =
  687. (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  688. igp_lane_info = dig_connector->igp_lane_info;
  689. }
  690. if (encoder->crtc) {
  691. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  692. pll_id = radeon_crtc->pll_id;
  693. }
  694. /* no dig encoder assigned */
  695. if (dig_encoder == -1)
  696. return;
  697. if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)))
  698. is_dp = true;
  699. memset(&args, 0, sizeof(args));
  700. switch (radeon_encoder->encoder_id) {
  701. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  702. index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
  703. break;
  704. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  705. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  706. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  707. index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
  708. break;
  709. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  710. index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl);
  711. break;
  712. }
  713. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  714. return;
  715. switch (frev) {
  716. case 1:
  717. switch (crev) {
  718. case 1:
  719. args.v1.ucAction = action;
  720. if (action == ATOM_TRANSMITTER_ACTION_INIT) {
  721. args.v1.usInitInfo = cpu_to_le16(connector_object_id);
  722. } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
  723. args.v1.asMode.ucLaneSel = lane_num;
  724. args.v1.asMode.ucLaneSet = lane_set;
  725. } else {
  726. if (is_dp)
  727. args.v1.usPixelClock =
  728. cpu_to_le16(dp_clock / 10);
  729. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  730. args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
  731. else
  732. args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  733. }
  734. args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
  735. if (dig_encoder)
  736. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
  737. else
  738. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
  739. if ((rdev->flags & RADEON_IS_IGP) &&
  740. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) {
  741. if (is_dp ||
  742. !radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) {
  743. if (igp_lane_info & 0x1)
  744. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
  745. else if (igp_lane_info & 0x2)
  746. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7;
  747. else if (igp_lane_info & 0x4)
  748. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11;
  749. else if (igp_lane_info & 0x8)
  750. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
  751. } else {
  752. if (igp_lane_info & 0x3)
  753. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
  754. else if (igp_lane_info & 0xc)
  755. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
  756. }
  757. }
  758. if (dig->linkb)
  759. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
  760. else
  761. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
  762. if (is_dp)
  763. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
  764. else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  765. if (dig->coherent_mode)
  766. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
  767. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  768. args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
  769. }
  770. break;
  771. case 2:
  772. args.v2.ucAction = action;
  773. if (action == ATOM_TRANSMITTER_ACTION_INIT) {
  774. args.v2.usInitInfo = cpu_to_le16(connector_object_id);
  775. } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
  776. args.v2.asMode.ucLaneSel = lane_num;
  777. args.v2.asMode.ucLaneSet = lane_set;
  778. } else {
  779. if (is_dp)
  780. args.v2.usPixelClock =
  781. cpu_to_le16(dp_clock / 10);
  782. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  783. args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
  784. else
  785. args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  786. }
  787. args.v2.acConfig.ucEncoderSel = dig_encoder;
  788. if (dig->linkb)
  789. args.v2.acConfig.ucLinkSel = 1;
  790. switch (radeon_encoder->encoder_id) {
  791. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  792. args.v2.acConfig.ucTransmitterSel = 0;
  793. break;
  794. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  795. args.v2.acConfig.ucTransmitterSel = 1;
  796. break;
  797. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  798. args.v2.acConfig.ucTransmitterSel = 2;
  799. break;
  800. }
  801. if (is_dp) {
  802. args.v2.acConfig.fCoherentMode = 1;
  803. args.v2.acConfig.fDPConnector = 1;
  804. } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  805. if (dig->coherent_mode)
  806. args.v2.acConfig.fCoherentMode = 1;
  807. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  808. args.v2.acConfig.fDualLinkConnector = 1;
  809. }
  810. break;
  811. case 3:
  812. args.v3.ucAction = action;
  813. if (action == ATOM_TRANSMITTER_ACTION_INIT) {
  814. args.v3.usInitInfo = cpu_to_le16(connector_object_id);
  815. } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
  816. args.v3.asMode.ucLaneSel = lane_num;
  817. args.v3.asMode.ucLaneSet = lane_set;
  818. } else {
  819. if (is_dp)
  820. args.v3.usPixelClock =
  821. cpu_to_le16(dp_clock / 10);
  822. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  823. args.v3.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
  824. else
  825. args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  826. }
  827. if (is_dp)
  828. args.v3.ucLaneNum = dp_lane_count;
  829. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  830. args.v3.ucLaneNum = 8;
  831. else
  832. args.v3.ucLaneNum = 4;
  833. if (dig->linkb)
  834. args.v3.acConfig.ucLinkSel = 1;
  835. if (dig_encoder & 1)
  836. args.v3.acConfig.ucEncoderSel = 1;
  837. /* Select the PLL for the PHY
  838. * DP PHY should be clocked from external src if there is
  839. * one.
  840. */
  841. /* On DCE4, if there is an external clock, it generates the DP ref clock */
  842. if (is_dp && rdev->clock.dp_extclk)
  843. args.v3.acConfig.ucRefClkSource = 2; /* external src */
  844. else
  845. args.v3.acConfig.ucRefClkSource = pll_id;
  846. switch (radeon_encoder->encoder_id) {
  847. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  848. args.v3.acConfig.ucTransmitterSel = 0;
  849. break;
  850. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  851. args.v3.acConfig.ucTransmitterSel = 1;
  852. break;
  853. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  854. args.v3.acConfig.ucTransmitterSel = 2;
  855. break;
  856. }
  857. if (is_dp)
  858. args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */
  859. else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  860. if (dig->coherent_mode)
  861. args.v3.acConfig.fCoherentMode = 1;
  862. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  863. args.v3.acConfig.fDualLinkConnector = 1;
  864. }
  865. break;
  866. case 4:
  867. args.v4.ucAction = action;
  868. if (action == ATOM_TRANSMITTER_ACTION_INIT) {
  869. args.v4.usInitInfo = cpu_to_le16(connector_object_id);
  870. } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
  871. args.v4.asMode.ucLaneSel = lane_num;
  872. args.v4.asMode.ucLaneSet = lane_set;
  873. } else {
  874. if (is_dp)
  875. args.v4.usPixelClock =
  876. cpu_to_le16(dp_clock / 10);
  877. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  878. args.v4.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
  879. else
  880. args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  881. }
  882. if (is_dp)
  883. args.v4.ucLaneNum = dp_lane_count;
  884. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  885. args.v4.ucLaneNum = 8;
  886. else
  887. args.v4.ucLaneNum = 4;
  888. if (dig->linkb)
  889. args.v4.acConfig.ucLinkSel = 1;
  890. if (dig_encoder & 1)
  891. args.v4.acConfig.ucEncoderSel = 1;
  892. /* Select the PLL for the PHY
  893. * DP PHY should be clocked from external src if there is
  894. * one.
  895. */
  896. /* On DCE5 DCPLL usually generates the DP ref clock */
  897. if (is_dp) {
  898. if (rdev->clock.dp_extclk)
  899. args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK;
  900. else
  901. args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL;
  902. } else
  903. args.v4.acConfig.ucRefClkSource = pll_id;
  904. switch (radeon_encoder->encoder_id) {
  905. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  906. args.v4.acConfig.ucTransmitterSel = 0;
  907. break;
  908. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  909. args.v4.acConfig.ucTransmitterSel = 1;
  910. break;
  911. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  912. args.v4.acConfig.ucTransmitterSel = 2;
  913. break;
  914. }
  915. if (is_dp)
  916. args.v4.acConfig.fCoherentMode = 1; /* DP requires coherent */
  917. else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  918. if (dig->coherent_mode)
  919. args.v4.acConfig.fCoherentMode = 1;
  920. if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  921. args.v4.acConfig.fDualLinkConnector = 1;
  922. }
  923. break;
  924. case 5:
  925. args.v5.ucAction = action;
  926. if (is_dp)
  927. args.v5.usSymClock = cpu_to_le16(dp_clock / 10);
  928. else
  929. args.v5.usSymClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  930. switch (radeon_encoder->encoder_id) {
  931. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  932. if (dig->linkb)
  933. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYB;
  934. else
  935. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYA;
  936. break;
  937. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  938. if (dig->linkb)
  939. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYD;
  940. else
  941. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYC;
  942. break;
  943. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  944. if (dig->linkb)
  945. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYF;
  946. else
  947. args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYE;
  948. break;
  949. }
  950. if (is_dp)
  951. args.v5.ucLaneNum = dp_lane_count;
  952. else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  953. args.v5.ucLaneNum = 8;
  954. else
  955. args.v5.ucLaneNum = 4;
  956. args.v5.ucConnObjId = connector_object_id;
  957. args.v5.ucDigMode = atombios_get_encoder_mode(encoder);
  958. if (is_dp && rdev->clock.dp_extclk)
  959. args.v5.asConfig.ucPhyClkSrcId = ENCODER_REFCLK_SRC_EXTCLK;
  960. else
  961. args.v5.asConfig.ucPhyClkSrcId = pll_id;
  962. if (is_dp)
  963. args.v5.asConfig.ucCoherentMode = 1; /* DP requires coherent */
  964. else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  965. if (dig->coherent_mode)
  966. args.v5.asConfig.ucCoherentMode = 1;
  967. }
  968. if (hpd_id == RADEON_HPD_NONE)
  969. args.v5.asConfig.ucHPDSel = 0;
  970. else
  971. args.v5.asConfig.ucHPDSel = hpd_id + 1;
  972. args.v5.ucDigEncoderSel = 1 << dig_encoder;
  973. args.v5.ucDPLaneSet = lane_set;
  974. break;
  975. default:
  976. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  977. break;
  978. }
  979. break;
  980. default:
  981. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  982. break;
  983. }
  984. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  985. }
  986. bool
  987. atombios_set_edp_panel_power(struct drm_connector *connector, int action)
  988. {
  989. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  990. struct drm_device *dev = radeon_connector->base.dev;
  991. struct radeon_device *rdev = dev->dev_private;
  992. union dig_transmitter_control args;
  993. int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
  994. uint8_t frev, crev;
  995. if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
  996. goto done;
  997. if (!ASIC_IS_DCE4(rdev))
  998. goto done;
  999. if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) &&
  1000. (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
  1001. goto done;
  1002. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  1003. goto done;
  1004. memset(&args, 0, sizeof(args));
  1005. args.v1.ucAction = action;
  1006. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1007. /* wait for the panel to power up */
  1008. if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) {
  1009. int i;
  1010. for (i = 0; i < 300; i++) {
  1011. if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
  1012. return true;
  1013. mdelay(1);
  1014. }
  1015. return false;
  1016. }
  1017. done:
  1018. return true;
  1019. }
  1020. union external_encoder_control {
  1021. EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
  1022. EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3;
  1023. };
  1024. static void
  1025. atombios_external_encoder_setup(struct drm_encoder *encoder,
  1026. struct drm_encoder *ext_encoder,
  1027. int action)
  1028. {
  1029. struct drm_device *dev = encoder->dev;
  1030. struct radeon_device *rdev = dev->dev_private;
  1031. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1032. struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder);
  1033. union external_encoder_control args;
  1034. struct drm_connector *connector;
  1035. int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
  1036. u8 frev, crev;
  1037. int dp_clock = 0;
  1038. int dp_lane_count = 0;
  1039. int connector_object_id = 0;
  1040. u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1041. int bpc = 8;
  1042. if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
  1043. connector = radeon_get_connector_for_encoder_init(encoder);
  1044. else
  1045. connector = radeon_get_connector_for_encoder(encoder);
  1046. if (connector) {
  1047. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1048. struct radeon_connector_atom_dig *dig_connector =
  1049. radeon_connector->con_priv;
  1050. dp_clock = dig_connector->dp_clock;
  1051. dp_lane_count = dig_connector->dp_lane_count;
  1052. connector_object_id =
  1053. (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  1054. /* bpc = connector->display_info.bpc; */
  1055. }
  1056. memset(&args, 0, sizeof(args));
  1057. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  1058. return;
  1059. switch (frev) {
  1060. case 1:
  1061. /* no params on frev 1 */
  1062. break;
  1063. case 2:
  1064. switch (crev) {
  1065. case 1:
  1066. case 2:
  1067. args.v1.sDigEncoder.ucAction = action;
  1068. args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  1069. args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
  1070. if (ENCODER_MODE_IS_DP(args.v1.sDigEncoder.ucEncoderMode)) {
  1071. if (dp_clock == 270000)
  1072. args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
  1073. args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
  1074. } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  1075. args.v1.sDigEncoder.ucLaneNum = 8;
  1076. else
  1077. args.v1.sDigEncoder.ucLaneNum = 4;
  1078. break;
  1079. case 3:
  1080. args.v3.sExtEncoder.ucAction = action;
  1081. if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
  1082. args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id);
  1083. else
  1084. args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
  1085. args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
  1086. if (ENCODER_MODE_IS_DP(args.v3.sExtEncoder.ucEncoderMode)) {
  1087. if (dp_clock == 270000)
  1088. args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
  1089. else if (dp_clock == 540000)
  1090. args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ;
  1091. args.v3.sExtEncoder.ucLaneNum = dp_lane_count;
  1092. } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
  1093. args.v3.sExtEncoder.ucLaneNum = 8;
  1094. else
  1095. args.v3.sExtEncoder.ucLaneNum = 4;
  1096. switch (ext_enum) {
  1097. case GRAPH_OBJECT_ENUM_ID1:
  1098. args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1;
  1099. break;
  1100. case GRAPH_OBJECT_ENUM_ID2:
  1101. args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2;
  1102. break;
  1103. case GRAPH_OBJECT_ENUM_ID3:
  1104. args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3;
  1105. break;
  1106. }
  1107. switch (bpc) {
  1108. case 0:
  1109. args.v3.sExtEncoder.ucBitPerColor = PANEL_BPC_UNDEFINE;
  1110. break;
  1111. case 6:
  1112. args.v3.sExtEncoder.ucBitPerColor = PANEL_6BIT_PER_COLOR;
  1113. break;
  1114. case 8:
  1115. default:
  1116. args.v3.sExtEncoder.ucBitPerColor = PANEL_8BIT_PER_COLOR;
  1117. break;
  1118. case 10:
  1119. args.v3.sExtEncoder.ucBitPerColor = PANEL_10BIT_PER_COLOR;
  1120. break;
  1121. case 12:
  1122. args.v3.sExtEncoder.ucBitPerColor = PANEL_12BIT_PER_COLOR;
  1123. break;
  1124. case 16:
  1125. args.v3.sExtEncoder.ucBitPerColor = PANEL_16BIT_PER_COLOR;
  1126. break;
  1127. }
  1128. break;
  1129. default:
  1130. DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
  1131. return;
  1132. }
  1133. break;
  1134. default:
  1135. DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
  1136. return;
  1137. }
  1138. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1139. }
  1140. static void
  1141. atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
  1142. {
  1143. struct drm_device *dev = encoder->dev;
  1144. struct radeon_device *rdev = dev->dev_private;
  1145. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1146. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1147. ENABLE_YUV_PS_ALLOCATION args;
  1148. int index = GetIndexIntoMasterTable(COMMAND, EnableYUV);
  1149. uint32_t temp, reg;
  1150. memset(&args, 0, sizeof(args));
  1151. if (rdev->family >= CHIP_R600)
  1152. reg = R600_BIOS_3_SCRATCH;
  1153. else
  1154. reg = RADEON_BIOS_3_SCRATCH;
  1155. /* XXX: fix up scratch reg handling */
  1156. temp = RREG32(reg);
  1157. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1158. WREG32(reg, (ATOM_S3_TV1_ACTIVE |
  1159. (radeon_crtc->crtc_id << 18)));
  1160. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1161. WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24)));
  1162. else
  1163. WREG32(reg, 0);
  1164. if (enable)
  1165. args.ucEnable = ATOM_ENABLE;
  1166. args.ucCRTC = radeon_crtc->crtc_id;
  1167. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1168. WREG32(reg, temp);
  1169. }
  1170. static void
  1171. radeon_atom_encoder_dpms_avivo(struct drm_encoder *encoder, int mode)
  1172. {
  1173. struct drm_device *dev = encoder->dev;
  1174. struct radeon_device *rdev = dev->dev_private;
  1175. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1176. DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
  1177. int index = 0;
  1178. memset(&args, 0, sizeof(args));
  1179. switch (radeon_encoder->encoder_id) {
  1180. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1181. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  1182. index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl);
  1183. break;
  1184. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1185. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  1186. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1187. index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
  1188. break;
  1189. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1190. index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
  1191. break;
  1192. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  1193. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  1194. index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
  1195. else
  1196. index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl);
  1197. break;
  1198. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1199. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1200. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1201. index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
  1202. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1203. index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
  1204. else
  1205. index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
  1206. break;
  1207. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1208. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1209. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1210. index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
  1211. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1212. index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
  1213. else
  1214. index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
  1215. break;
  1216. default:
  1217. return;
  1218. }
  1219. switch (mode) {
  1220. case DRM_MODE_DPMS_ON:
  1221. args.ucAction = ATOM_ENABLE;
  1222. /* workaround for DVOOutputControl on some RS690 systems */
  1223. if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) {
  1224. u32 reg = RREG32(RADEON_BIOS_3_SCRATCH);
  1225. WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE);
  1226. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1227. WREG32(RADEON_BIOS_3_SCRATCH, reg);
  1228. } else
  1229. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1230. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  1231. args.ucAction = ATOM_LCD_BLON;
  1232. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1233. }
  1234. break;
  1235. case DRM_MODE_DPMS_STANDBY:
  1236. case DRM_MODE_DPMS_SUSPEND:
  1237. case DRM_MODE_DPMS_OFF:
  1238. args.ucAction = ATOM_DISABLE;
  1239. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1240. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  1241. args.ucAction = ATOM_LCD_BLOFF;
  1242. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1243. }
  1244. break;
  1245. }
  1246. }
  1247. static void
  1248. radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode)
  1249. {
  1250. struct drm_device *dev = encoder->dev;
  1251. struct radeon_device *rdev = dev->dev_private;
  1252. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1253. struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
  1254. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  1255. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1256. struct radeon_connector *radeon_connector = NULL;
  1257. struct radeon_connector_atom_dig *radeon_dig_connector = NULL;
  1258. if (connector) {
  1259. radeon_connector = to_radeon_connector(connector);
  1260. radeon_dig_connector = radeon_connector->con_priv;
  1261. }
  1262. switch (mode) {
  1263. case DRM_MODE_DPMS_ON:
  1264. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1265. if (!connector)
  1266. dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE;
  1267. else
  1268. dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector);
  1269. /* setup and enable the encoder */
  1270. atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
  1271. atombios_dig_encoder_setup(encoder,
  1272. ATOM_ENCODER_CMD_SETUP_PANEL_MODE,
  1273. dig->panel_mode);
  1274. if (ext_encoder) {
  1275. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))
  1276. atombios_external_encoder_setup(encoder, ext_encoder,
  1277. EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP);
  1278. }
  1279. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
  1280. } else if (ASIC_IS_DCE4(rdev)) {
  1281. /* setup and enable the encoder */
  1282. atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
  1283. /* enable the transmitter */
  1284. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
  1285. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
  1286. } else {
  1287. /* setup and enable the encoder and transmitter */
  1288. atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0);
  1289. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
  1290. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
  1291. /* some dce3.x boards have a bug in their transmitter control table.
  1292. * ACTION_ENABLE_OUTPUT can probably be dropped since ACTION_ENABLE
  1293. * does the same thing and more.
  1294. */
  1295. if ((rdev->family != CHIP_RV710) && (rdev->family != CHIP_RV730) &&
  1296. (rdev->family != CHIP_RS780) && (rdev->family != CHIP_RS880))
  1297. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
  1298. }
  1299. if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
  1300. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
  1301. atombios_set_edp_panel_power(connector,
  1302. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1303. radeon_dig_connector->edp_on = true;
  1304. }
  1305. radeon_dp_link_train(encoder, connector);
  1306. if (ASIC_IS_DCE4(rdev))
  1307. atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0);
  1308. }
  1309. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  1310. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
  1311. break;
  1312. case DRM_MODE_DPMS_STANDBY:
  1313. case DRM_MODE_DPMS_SUSPEND:
  1314. case DRM_MODE_DPMS_OFF:
  1315. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1316. /* disable the transmitter */
  1317. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
  1318. } else if (ASIC_IS_DCE4(rdev)) {
  1319. /* disable the transmitter */
  1320. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
  1321. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
  1322. } else {
  1323. /* disable the encoder and transmitter */
  1324. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
  1325. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
  1326. atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
  1327. }
  1328. if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
  1329. if (ASIC_IS_DCE4(rdev))
  1330. atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
  1331. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
  1332. atombios_set_edp_panel_power(connector,
  1333. ATOM_TRANSMITTER_ACTION_POWER_OFF);
  1334. radeon_dig_connector->edp_on = false;
  1335. }
  1336. }
  1337. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  1338. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
  1339. break;
  1340. }
  1341. }
  1342. static void
  1343. radeon_atom_encoder_dpms_ext(struct drm_encoder *encoder,
  1344. struct drm_encoder *ext_encoder,
  1345. int mode)
  1346. {
  1347. struct drm_device *dev = encoder->dev;
  1348. struct radeon_device *rdev = dev->dev_private;
  1349. switch (mode) {
  1350. case DRM_MODE_DPMS_ON:
  1351. default:
  1352. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) {
  1353. atombios_external_encoder_setup(encoder, ext_encoder,
  1354. EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT);
  1355. atombios_external_encoder_setup(encoder, ext_encoder,
  1356. EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING_OFF);
  1357. } else
  1358. atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
  1359. break;
  1360. case DRM_MODE_DPMS_STANDBY:
  1361. case DRM_MODE_DPMS_SUSPEND:
  1362. case DRM_MODE_DPMS_OFF:
  1363. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) {
  1364. atombios_external_encoder_setup(encoder, ext_encoder,
  1365. EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING);
  1366. atombios_external_encoder_setup(encoder, ext_encoder,
  1367. EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT);
  1368. } else
  1369. atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE);
  1370. break;
  1371. }
  1372. }
  1373. static void
  1374. radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
  1375. {
  1376. struct drm_device *dev = encoder->dev;
  1377. struct radeon_device *rdev = dev->dev_private;
  1378. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1379. struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
  1380. DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
  1381. radeon_encoder->encoder_id, mode, radeon_encoder->devices,
  1382. radeon_encoder->active_device);
  1383. switch (radeon_encoder->encoder_id) {
  1384. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1385. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  1386. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1387. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  1388. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1389. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  1390. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1391. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1392. radeon_atom_encoder_dpms_avivo(encoder, mode);
  1393. break;
  1394. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1395. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1396. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1397. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  1398. radeon_atom_encoder_dpms_dig(encoder, mode);
  1399. break;
  1400. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1401. if (ASIC_IS_DCE5(rdev)) {
  1402. switch (mode) {
  1403. case DRM_MODE_DPMS_ON:
  1404. atombios_dvo_setup(encoder, ATOM_ENABLE);
  1405. break;
  1406. case DRM_MODE_DPMS_STANDBY:
  1407. case DRM_MODE_DPMS_SUSPEND:
  1408. case DRM_MODE_DPMS_OFF:
  1409. atombios_dvo_setup(encoder, ATOM_DISABLE);
  1410. break;
  1411. }
  1412. } else if (ASIC_IS_DCE3(rdev))
  1413. radeon_atom_encoder_dpms_dig(encoder, mode);
  1414. else
  1415. radeon_atom_encoder_dpms_avivo(encoder, mode);
  1416. break;
  1417. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1418. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1419. if (ASIC_IS_DCE5(rdev)) {
  1420. switch (mode) {
  1421. case DRM_MODE_DPMS_ON:
  1422. atombios_dac_setup(encoder, ATOM_ENABLE);
  1423. break;
  1424. case DRM_MODE_DPMS_STANDBY:
  1425. case DRM_MODE_DPMS_SUSPEND:
  1426. case DRM_MODE_DPMS_OFF:
  1427. atombios_dac_setup(encoder, ATOM_DISABLE);
  1428. break;
  1429. }
  1430. } else
  1431. radeon_atom_encoder_dpms_avivo(encoder, mode);
  1432. break;
  1433. default:
  1434. return;
  1435. }
  1436. if (ext_encoder)
  1437. radeon_atom_encoder_dpms_ext(encoder, ext_encoder, mode);
  1438. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  1439. }
  1440. union crtc_source_param {
  1441. SELECT_CRTC_SOURCE_PS_ALLOCATION v1;
  1442. SELECT_CRTC_SOURCE_PARAMETERS_V2 v2;
  1443. };
  1444. static void
  1445. atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
  1446. {
  1447. struct drm_device *dev = encoder->dev;
  1448. struct radeon_device *rdev = dev->dev_private;
  1449. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1450. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1451. union crtc_source_param args;
  1452. int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source);
  1453. uint8_t frev, crev;
  1454. struct radeon_encoder_atom_dig *dig;
  1455. memset(&args, 0, sizeof(args));
  1456. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  1457. return;
  1458. switch (frev) {
  1459. case 1:
  1460. switch (crev) {
  1461. case 1:
  1462. default:
  1463. if (ASIC_IS_AVIVO(rdev))
  1464. args.v1.ucCRTC = radeon_crtc->crtc_id;
  1465. else {
  1466. if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) {
  1467. args.v1.ucCRTC = radeon_crtc->crtc_id;
  1468. } else {
  1469. args.v1.ucCRTC = radeon_crtc->crtc_id << 2;
  1470. }
  1471. }
  1472. switch (radeon_encoder->encoder_id) {
  1473. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1474. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  1475. args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX;
  1476. break;
  1477. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1478. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  1479. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT)
  1480. args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX;
  1481. else
  1482. args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX;
  1483. break;
  1484. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1485. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  1486. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1487. args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX;
  1488. break;
  1489. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1490. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1491. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1492. args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
  1493. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1494. args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
  1495. else
  1496. args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX;
  1497. break;
  1498. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1499. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1500. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1501. args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
  1502. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1503. args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
  1504. else
  1505. args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX;
  1506. break;
  1507. }
  1508. break;
  1509. case 2:
  1510. args.v2.ucCRTC = radeon_crtc->crtc_id;
  1511. if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) {
  1512. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1513. if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
  1514. args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
  1515. else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
  1516. args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT;
  1517. else
  1518. args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
  1519. } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  1520. args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
  1521. } else {
  1522. args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
  1523. }
  1524. switch (radeon_encoder->encoder_id) {
  1525. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1526. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1527. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1528. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  1529. dig = radeon_encoder->enc_priv;
  1530. switch (dig->dig_encoder) {
  1531. case 0:
  1532. args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
  1533. break;
  1534. case 1:
  1535. args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
  1536. break;
  1537. case 2:
  1538. args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID;
  1539. break;
  1540. case 3:
  1541. args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID;
  1542. break;
  1543. case 4:
  1544. args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID;
  1545. break;
  1546. case 5:
  1547. args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID;
  1548. break;
  1549. }
  1550. break;
  1551. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1552. args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
  1553. break;
  1554. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1555. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1556. args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
  1557. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1558. args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
  1559. else
  1560. args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID;
  1561. break;
  1562. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1563. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  1564. args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
  1565. else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
  1566. args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
  1567. else
  1568. args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID;
  1569. break;
  1570. }
  1571. break;
  1572. }
  1573. break;
  1574. default:
  1575. DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
  1576. return;
  1577. }
  1578. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1579. /* update scratch regs with new routing */
  1580. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  1581. }
  1582. static void
  1583. atombios_apply_encoder_quirks(struct drm_encoder *encoder,
  1584. struct drm_display_mode *mode)
  1585. {
  1586. struct drm_device *dev = encoder->dev;
  1587. struct radeon_device *rdev = dev->dev_private;
  1588. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1589. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1590. /* Funky macbooks */
  1591. if ((dev->pdev->device == 0x71C5) &&
  1592. (dev->pdev->subsystem_vendor == 0x106b) &&
  1593. (dev->pdev->subsystem_device == 0x0080)) {
  1594. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1595. uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL);
  1596. lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN;
  1597. lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN;
  1598. WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control);
  1599. }
  1600. }
  1601. /* set scaler clears this on some chips */
  1602. if (ASIC_IS_AVIVO(rdev) &&
  1603. (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) {
  1604. if (ASIC_IS_DCE4(rdev)) {
  1605. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1606. WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset,
  1607. EVERGREEN_INTERLEAVE_EN);
  1608. else
  1609. WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
  1610. } else {
  1611. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1612. WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
  1613. AVIVO_D1MODE_INTERLEAVE_EN);
  1614. else
  1615. WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
  1616. }
  1617. }
  1618. }
  1619. static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder)
  1620. {
  1621. struct drm_device *dev = encoder->dev;
  1622. struct radeon_device *rdev = dev->dev_private;
  1623. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1624. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1625. struct drm_encoder *test_encoder;
  1626. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  1627. uint32_t dig_enc_in_use = 0;
  1628. if (ASIC_IS_DCE6(rdev)) {
  1629. /* DCE6 */
  1630. switch (radeon_encoder->encoder_id) {
  1631. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1632. if (dig->linkb)
  1633. return 1;
  1634. else
  1635. return 0;
  1636. break;
  1637. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1638. if (dig->linkb)
  1639. return 3;
  1640. else
  1641. return 2;
  1642. break;
  1643. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1644. if (dig->linkb)
  1645. return 5;
  1646. else
  1647. return 4;
  1648. break;
  1649. }
  1650. } else if (ASIC_IS_DCE4(rdev)) {
  1651. /* DCE4/5 */
  1652. if (ASIC_IS_DCE41(rdev) && !ASIC_IS_DCE61(rdev)) {
  1653. /* ontario follows DCE4 */
  1654. if (rdev->family == CHIP_PALM) {
  1655. if (dig->linkb)
  1656. return 1;
  1657. else
  1658. return 0;
  1659. } else
  1660. /* llano follows DCE3.2 */
  1661. return radeon_crtc->crtc_id;
  1662. } else {
  1663. switch (radeon_encoder->encoder_id) {
  1664. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1665. if (dig->linkb)
  1666. return 1;
  1667. else
  1668. return 0;
  1669. break;
  1670. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1671. if (dig->linkb)
  1672. return 3;
  1673. else
  1674. return 2;
  1675. break;
  1676. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1677. if (dig->linkb)
  1678. return 5;
  1679. else
  1680. return 4;
  1681. break;
  1682. }
  1683. }
  1684. }
  1685. /* on DCE32 and encoder can driver any block so just crtc id */
  1686. if (ASIC_IS_DCE32(rdev)) {
  1687. return radeon_crtc->crtc_id;
  1688. }
  1689. /* on DCE3 - LVTMA can only be driven by DIGB */
  1690. list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
  1691. struct radeon_encoder *radeon_test_encoder;
  1692. if (encoder == test_encoder)
  1693. continue;
  1694. if (!radeon_encoder_is_digital(test_encoder))
  1695. continue;
  1696. radeon_test_encoder = to_radeon_encoder(test_encoder);
  1697. dig = radeon_test_encoder->enc_priv;
  1698. if (dig->dig_encoder >= 0)
  1699. dig_enc_in_use |= (1 << dig->dig_encoder);
  1700. }
  1701. if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) {
  1702. if (dig_enc_in_use & 0x2)
  1703. DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
  1704. return 1;
  1705. }
  1706. if (!(dig_enc_in_use & 1))
  1707. return 0;
  1708. return 1;
  1709. }
  1710. /* This only needs to be called once at startup */
  1711. void
  1712. radeon_atom_encoder_init(struct radeon_device *rdev)
  1713. {
  1714. struct drm_device *dev = rdev->ddev;
  1715. struct drm_encoder *encoder;
  1716. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1717. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1718. struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
  1719. switch (radeon_encoder->encoder_id) {
  1720. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1721. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1722. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1723. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  1724. atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
  1725. break;
  1726. default:
  1727. break;
  1728. }
  1729. if (ext_encoder && (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)))
  1730. atombios_external_encoder_setup(encoder, ext_encoder,
  1731. EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT);
  1732. }
  1733. }
  1734. static void
  1735. radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
  1736. struct drm_display_mode *mode,
  1737. struct drm_display_mode *adjusted_mode)
  1738. {
  1739. struct drm_device *dev = encoder->dev;
  1740. struct radeon_device *rdev = dev->dev_private;
  1741. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1742. radeon_encoder->pixel_clock = adjusted_mode->clock;
  1743. /* need to call this here rather than in prepare() since we need some crtc info */
  1744. radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  1745. if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) {
  1746. if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT))
  1747. atombios_yuv_setup(encoder, true);
  1748. else
  1749. atombios_yuv_setup(encoder, false);
  1750. }
  1751. switch (radeon_encoder->encoder_id) {
  1752. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1753. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  1754. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1755. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  1756. atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
  1757. break;
  1758. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1759. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1760. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1761. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  1762. /* handled in dpms */
  1763. break;
  1764. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  1765. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1766. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1767. atombios_dvo_setup(encoder, ATOM_ENABLE);
  1768. break;
  1769. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1770. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1771. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1772. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1773. atombios_dac_setup(encoder, ATOM_ENABLE);
  1774. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) {
  1775. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  1776. atombios_tv_setup(encoder, ATOM_ENABLE);
  1777. else
  1778. atombios_tv_setup(encoder, ATOM_DISABLE);
  1779. }
  1780. break;
  1781. }
  1782. atombios_apply_encoder_quirks(encoder, adjusted_mode);
  1783. if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
  1784. r600_hdmi_enable(encoder);
  1785. r600_hdmi_setmode(encoder, adjusted_mode);
  1786. }
  1787. }
  1788. static bool
  1789. atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  1790. {
  1791. struct drm_device *dev = encoder->dev;
  1792. struct radeon_device *rdev = dev->dev_private;
  1793. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1794. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1795. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT |
  1796. ATOM_DEVICE_CV_SUPPORT |
  1797. ATOM_DEVICE_CRT_SUPPORT)) {
  1798. DAC_LOAD_DETECTION_PS_ALLOCATION args;
  1799. int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection);
  1800. uint8_t frev, crev;
  1801. memset(&args, 0, sizeof(args));
  1802. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  1803. return false;
  1804. args.sDacload.ucMisc = 0;
  1805. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) ||
  1806. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1))
  1807. args.sDacload.ucDacType = ATOM_DAC_A;
  1808. else
  1809. args.sDacload.ucDacType = ATOM_DAC_B;
  1810. if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)
  1811. args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT);
  1812. else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)
  1813. args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT);
  1814. else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
  1815. args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT);
  1816. if (crev >= 3)
  1817. args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
  1818. } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1819. args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT);
  1820. if (crev >= 3)
  1821. args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
  1822. }
  1823. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1824. return true;
  1825. } else
  1826. return false;
  1827. }
  1828. static enum drm_connector_status
  1829. radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  1830. {
  1831. struct drm_device *dev = encoder->dev;
  1832. struct radeon_device *rdev = dev->dev_private;
  1833. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1834. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1835. uint32_t bios_0_scratch;
  1836. if (!atombios_dac_load_detect(encoder, connector)) {
  1837. DRM_DEBUG_KMS("detect returned false \n");
  1838. return connector_status_unknown;
  1839. }
  1840. if (rdev->family >= CHIP_R600)
  1841. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1842. else
  1843. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  1844. DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
  1845. if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1846. if (bios_0_scratch & ATOM_S0_CRT1_MASK)
  1847. return connector_status_connected;
  1848. }
  1849. if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1850. if (bios_0_scratch & ATOM_S0_CRT2_MASK)
  1851. return connector_status_connected;
  1852. }
  1853. if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
  1854. if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
  1855. return connector_status_connected;
  1856. }
  1857. if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1858. if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
  1859. return connector_status_connected; /* CTV */
  1860. else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
  1861. return connector_status_connected; /* STV */
  1862. }
  1863. return connector_status_disconnected;
  1864. }
  1865. static enum drm_connector_status
  1866. radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  1867. {
  1868. struct drm_device *dev = encoder->dev;
  1869. struct radeon_device *rdev = dev->dev_private;
  1870. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1871. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1872. struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
  1873. u32 bios_0_scratch;
  1874. if (!ASIC_IS_DCE4(rdev))
  1875. return connector_status_unknown;
  1876. if (!ext_encoder)
  1877. return connector_status_unknown;
  1878. if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0)
  1879. return connector_status_unknown;
  1880. /* load detect on the dp bridge */
  1881. atombios_external_encoder_setup(encoder, ext_encoder,
  1882. EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION);
  1883. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1884. DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
  1885. if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1886. if (bios_0_scratch & ATOM_S0_CRT1_MASK)
  1887. return connector_status_connected;
  1888. }
  1889. if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1890. if (bios_0_scratch & ATOM_S0_CRT2_MASK)
  1891. return connector_status_connected;
  1892. }
  1893. if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
  1894. if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
  1895. return connector_status_connected;
  1896. }
  1897. if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1898. if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
  1899. return connector_status_connected; /* CTV */
  1900. else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
  1901. return connector_status_connected; /* STV */
  1902. }
  1903. return connector_status_disconnected;
  1904. }
  1905. void
  1906. radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder)
  1907. {
  1908. struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
  1909. if (ext_encoder)
  1910. /* ddc_setup on the dp bridge */
  1911. atombios_external_encoder_setup(encoder, ext_encoder,
  1912. EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP);
  1913. }
  1914. static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
  1915. {
  1916. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1917. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1918. if ((radeon_encoder->active_device &
  1919. (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  1920. (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
  1921. ENCODER_OBJECT_ID_NONE)) {
  1922. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  1923. if (dig)
  1924. dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder);
  1925. }
  1926. radeon_atom_output_lock(encoder, true);
  1927. if (connector) {
  1928. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1929. /* select the clock/data port if it uses a router */
  1930. if (radeon_connector->router.cd_valid)
  1931. radeon_router_select_cd_port(radeon_connector);
  1932. /* turn eDP panel on for mode set */
  1933. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  1934. atombios_set_edp_panel_power(connector,
  1935. ATOM_TRANSMITTER_ACTION_POWER_ON);
  1936. }
  1937. /* this is needed for the pll/ss setup to work correctly in some cases */
  1938. atombios_set_encoder_crtc_source(encoder);
  1939. }
  1940. static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
  1941. {
  1942. /* need to call this here as we need the crtc set up */
  1943. radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  1944. radeon_atom_output_lock(encoder, false);
  1945. }
  1946. static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
  1947. {
  1948. struct drm_device *dev = encoder->dev;
  1949. struct radeon_device *rdev = dev->dev_private;
  1950. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1951. struct radeon_encoder_atom_dig *dig;
  1952. /* check for pre-DCE3 cards with shared encoders;
  1953. * can't really use the links individually, so don't disable
  1954. * the encoder if it's in use by another connector
  1955. */
  1956. if (!ASIC_IS_DCE3(rdev)) {
  1957. struct drm_encoder *other_encoder;
  1958. struct radeon_encoder *other_radeon_encoder;
  1959. list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
  1960. other_radeon_encoder = to_radeon_encoder(other_encoder);
  1961. if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
  1962. drm_helper_encoder_in_use(other_encoder))
  1963. goto disable_done;
  1964. }
  1965. }
  1966. radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  1967. switch (radeon_encoder->encoder_id) {
  1968. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1969. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  1970. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1971. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  1972. atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE);
  1973. break;
  1974. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1975. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1976. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1977. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  1978. /* handled in dpms */
  1979. break;
  1980. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  1981. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1982. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  1983. atombios_dvo_setup(encoder, ATOM_DISABLE);
  1984. break;
  1985. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1986. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  1987. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1988. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  1989. atombios_dac_setup(encoder, ATOM_DISABLE);
  1990. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  1991. atombios_tv_setup(encoder, ATOM_DISABLE);
  1992. break;
  1993. }
  1994. disable_done:
  1995. if (radeon_encoder_is_digital(encoder)) {
  1996. if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  1997. r600_hdmi_disable(encoder);
  1998. dig = radeon_encoder->enc_priv;
  1999. dig->dig_encoder = -1;
  2000. }
  2001. radeon_encoder->active_device = 0;
  2002. }
  2003. /* these are handled by the primary encoders */
  2004. static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
  2005. {
  2006. }
  2007. static void radeon_atom_ext_commit(struct drm_encoder *encoder)
  2008. {
  2009. }
  2010. static void
  2011. radeon_atom_ext_mode_set(struct drm_encoder *encoder,
  2012. struct drm_display_mode *mode,
  2013. struct drm_display_mode *adjusted_mode)
  2014. {
  2015. }
  2016. static void radeon_atom_ext_disable(struct drm_encoder *encoder)
  2017. {
  2018. }
  2019. static void
  2020. radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
  2021. {
  2022. }
  2023. static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
  2024. struct drm_display_mode *mode,
  2025. struct drm_display_mode *adjusted_mode)
  2026. {
  2027. return true;
  2028. }
  2029. static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
  2030. .dpms = radeon_atom_ext_dpms,
  2031. .mode_fixup = radeon_atom_ext_mode_fixup,
  2032. .prepare = radeon_atom_ext_prepare,
  2033. .mode_set = radeon_atom_ext_mode_set,
  2034. .commit = radeon_atom_ext_commit,
  2035. .disable = radeon_atom_ext_disable,
  2036. /* no detect for TMDS/LVDS yet */
  2037. };
  2038. static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
  2039. .dpms = radeon_atom_encoder_dpms,
  2040. .mode_fixup = radeon_atom_mode_fixup,
  2041. .prepare = radeon_atom_encoder_prepare,
  2042. .mode_set = radeon_atom_encoder_mode_set,
  2043. .commit = radeon_atom_encoder_commit,
  2044. .disable = radeon_atom_encoder_disable,
  2045. .detect = radeon_atom_dig_detect,
  2046. };
  2047. static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = {
  2048. .dpms = radeon_atom_encoder_dpms,
  2049. .mode_fixup = radeon_atom_mode_fixup,
  2050. .prepare = radeon_atom_encoder_prepare,
  2051. .mode_set = radeon_atom_encoder_mode_set,
  2052. .commit = radeon_atom_encoder_commit,
  2053. .detect = radeon_atom_dac_detect,
  2054. };
  2055. void radeon_enc_destroy(struct drm_encoder *encoder)
  2056. {
  2057. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2058. kfree(radeon_encoder->enc_priv);
  2059. drm_encoder_cleanup(encoder);
  2060. kfree(radeon_encoder);
  2061. }
  2062. static const struct drm_encoder_funcs radeon_atom_enc_funcs = {
  2063. .destroy = radeon_enc_destroy,
  2064. };
  2065. struct radeon_encoder_atom_dac *
  2066. radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder)
  2067. {
  2068. struct drm_device *dev = radeon_encoder->base.dev;
  2069. struct radeon_device *rdev = dev->dev_private;
  2070. struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL);
  2071. if (!dac)
  2072. return NULL;
  2073. dac->tv_std = radeon_atombios_get_tv_info(rdev);
  2074. return dac;
  2075. }
  2076. struct radeon_encoder_atom_dig *
  2077. radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
  2078. {
  2079. int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  2080. struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  2081. if (!dig)
  2082. return NULL;
  2083. /* coherent mode by default */
  2084. dig->coherent_mode = true;
  2085. dig->dig_encoder = -1;
  2086. if (encoder_enum == 2)
  2087. dig->linkb = true;
  2088. else
  2089. dig->linkb = false;
  2090. return dig;
  2091. }
  2092. void
  2093. radeon_add_atom_encoder(struct drm_device *dev,
  2094. uint32_t encoder_enum,
  2095. uint32_t supported_device,
  2096. u16 caps)
  2097. {
  2098. struct radeon_device *rdev = dev->dev_private;
  2099. struct drm_encoder *encoder;
  2100. struct radeon_encoder *radeon_encoder;
  2101. /* see if we already added it */
  2102. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2103. radeon_encoder = to_radeon_encoder(encoder);
  2104. if (radeon_encoder->encoder_enum == encoder_enum) {
  2105. radeon_encoder->devices |= supported_device;
  2106. return;
  2107. }
  2108. }
  2109. /* add a new one */
  2110. radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
  2111. if (!radeon_encoder)
  2112. return;
  2113. encoder = &radeon_encoder->base;
  2114. switch (rdev->num_crtc) {
  2115. case 1:
  2116. encoder->possible_crtcs = 0x1;
  2117. break;
  2118. case 2:
  2119. default:
  2120. encoder->possible_crtcs = 0x3;
  2121. break;
  2122. case 4:
  2123. encoder->possible_crtcs = 0xf;
  2124. break;
  2125. case 6:
  2126. encoder->possible_crtcs = 0x3f;
  2127. break;
  2128. }
  2129. radeon_encoder->enc_priv = NULL;
  2130. radeon_encoder->encoder_enum = encoder_enum;
  2131. radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  2132. radeon_encoder->devices = supported_device;
  2133. radeon_encoder->rmx_type = RMX_OFF;
  2134. radeon_encoder->underscan_type = UNDERSCAN_OFF;
  2135. radeon_encoder->is_ext_encoder = false;
  2136. radeon_encoder->caps = caps;
  2137. switch (radeon_encoder->encoder_id) {
  2138. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  2139. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  2140. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  2141. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  2142. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  2143. radeon_encoder->rmx_type = RMX_FULL;
  2144. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
  2145. radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
  2146. } else {
  2147. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
  2148. radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
  2149. }
  2150. drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
  2151. break;
  2152. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  2153. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
  2154. radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
  2155. drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
  2156. break;
  2157. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  2158. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  2159. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  2160. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC);
  2161. radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
  2162. drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
  2163. break;
  2164. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  2165. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  2166. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  2167. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  2168. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  2169. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  2170. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  2171. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  2172. radeon_encoder->rmx_type = RMX_FULL;
  2173. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
  2174. radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
  2175. } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  2176. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
  2177. radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
  2178. } else {
  2179. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
  2180. radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
  2181. }
  2182. drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
  2183. break;
  2184. case ENCODER_OBJECT_ID_SI170B:
  2185. case ENCODER_OBJECT_ID_CH7303:
  2186. case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
  2187. case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
  2188. case ENCODER_OBJECT_ID_TITFP513:
  2189. case ENCODER_OBJECT_ID_VT1623:
  2190. case ENCODER_OBJECT_ID_HDMI_SI1930:
  2191. case ENCODER_OBJECT_ID_TRAVIS:
  2192. case ENCODER_OBJECT_ID_NUTMEG:
  2193. /* these are handled by the primary encoders */
  2194. radeon_encoder->is_ext_encoder = true;
  2195. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  2196. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
  2197. else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
  2198. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
  2199. else
  2200. drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
  2201. drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
  2202. break;
  2203. }
  2204. }