atombios_encoders.c 89 KB

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