radeon_atombios.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/radeon_drm.h>
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. /* from radeon_encoder.c */
  32. extern uint32_t
  33. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
  34. uint8_t dac);
  35. extern void radeon_link_encoder_connector(struct drm_device *dev);
  36. extern void
  37. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
  38. uint32_t supported_device, u16 caps);
  39. /* from radeon_connector.c */
  40. extern void
  41. radeon_add_atom_connector(struct drm_device *dev,
  42. uint32_t connector_id,
  43. uint32_t supported_device,
  44. int connector_type,
  45. struct radeon_i2c_bus_rec *i2c_bus,
  46. uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd,
  49. struct radeon_router *router);
  50. /* from radeon_legacy_encoder.c */
  51. extern void
  52. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  53. uint32_t supported_device);
  54. union atom_supported_devices {
  55. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  56. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  57. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  58. };
  59. static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
  60. ATOM_GPIO_I2C_ASSIGMENT *gpio,
  61. u8 index)
  62. {
  63. /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
  64. if ((rdev->family == CHIP_R420) ||
  65. (rdev->family == CHIP_R423) ||
  66. (rdev->family == CHIP_RV410)) {
  67. if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
  68. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
  69. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
  70. gpio->ucClkMaskShift = 0x19;
  71. gpio->ucDataMaskShift = 0x18;
  72. }
  73. }
  74. /* some evergreen boards have bad data for this entry */
  75. if (ASIC_IS_DCE4(rdev)) {
  76. if ((index == 7) &&
  77. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
  78. (gpio->sucI2cId.ucAccess == 0)) {
  79. gpio->sucI2cId.ucAccess = 0x97;
  80. gpio->ucDataMaskShift = 8;
  81. gpio->ucDataEnShift = 8;
  82. gpio->ucDataY_Shift = 8;
  83. gpio->ucDataA_Shift = 8;
  84. }
  85. }
  86. /* some DCE3 boards have bad data for this entry */
  87. if (ASIC_IS_DCE3(rdev)) {
  88. if ((index == 4) &&
  89. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
  90. (gpio->sucI2cId.ucAccess == 0x94))
  91. gpio->sucI2cId.ucAccess = 0x14;
  92. }
  93. }
  94. static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
  95. {
  96. struct radeon_i2c_bus_rec i2c;
  97. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  98. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  99. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  100. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  101. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  102. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  103. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  104. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  105. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  106. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  107. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  108. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  109. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  110. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  111. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  112. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  113. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  114. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  115. i2c.hw_capable = true;
  116. else
  117. i2c.hw_capable = false;
  118. if (gpio->sucI2cId.ucAccess == 0xa0)
  119. i2c.mm_i2c = true;
  120. else
  121. i2c.mm_i2c = false;
  122. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  123. if (i2c.mask_clk_reg)
  124. i2c.valid = true;
  125. else
  126. i2c.valid = false;
  127. return i2c;
  128. }
  129. static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  130. uint8_t id)
  131. {
  132. struct atom_context *ctx = rdev->mode_info.atom_context;
  133. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  134. struct radeon_i2c_bus_rec i2c;
  135. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  136. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  137. uint16_t data_offset, size;
  138. int i, num_indices;
  139. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  140. i2c.valid = false;
  141. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  142. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  143. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  144. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  145. for (i = 0; i < num_indices; i++) {
  146. gpio = &i2c_info->asGPIO_Info[i];
  147. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  148. if (gpio->sucI2cId.ucAccess == id) {
  149. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  150. break;
  151. }
  152. }
  153. }
  154. return i2c;
  155. }
  156. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  157. {
  158. struct atom_context *ctx = rdev->mode_info.atom_context;
  159. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  160. struct radeon_i2c_bus_rec i2c;
  161. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  162. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  163. uint16_t data_offset, size;
  164. int i, num_indices;
  165. char stmp[32];
  166. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  167. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  168. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  169. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  170. for (i = 0; i < num_indices; i++) {
  171. gpio = &i2c_info->asGPIO_Info[i];
  172. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  173. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  174. if (i2c.valid) {
  175. sprintf(stmp, "0x%x", i2c.i2c_id);
  176. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  177. }
  178. }
  179. }
  180. }
  181. static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  182. u8 id)
  183. {
  184. struct atom_context *ctx = rdev->mode_info.atom_context;
  185. struct radeon_gpio_rec gpio;
  186. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  187. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  188. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  189. u16 data_offset, size;
  190. int i, num_indices;
  191. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  192. gpio.valid = false;
  193. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  194. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  195. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  196. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  197. for (i = 0; i < num_indices; i++) {
  198. pin = &gpio_info->asGPIO_Pin[i];
  199. if (id == pin->ucGPIO_ID) {
  200. gpio.id = pin->ucGPIO_ID;
  201. gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
  202. gpio.mask = (1 << pin->ucGpioPinBitShift);
  203. gpio.valid = true;
  204. break;
  205. }
  206. }
  207. }
  208. return gpio;
  209. }
  210. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  211. struct radeon_gpio_rec *gpio)
  212. {
  213. struct radeon_hpd hpd;
  214. u32 reg;
  215. memset(&hpd, 0, sizeof(struct radeon_hpd));
  216. if (ASIC_IS_DCE6(rdev))
  217. reg = SI_DC_GPIO_HPD_A;
  218. else if (ASIC_IS_DCE4(rdev))
  219. reg = EVERGREEN_DC_GPIO_HPD_A;
  220. else
  221. reg = AVIVO_DC_GPIO_HPD_A;
  222. hpd.gpio = *gpio;
  223. if (gpio->reg == reg) {
  224. switch(gpio->mask) {
  225. case (1 << 0):
  226. hpd.hpd = RADEON_HPD_1;
  227. break;
  228. case (1 << 8):
  229. hpd.hpd = RADEON_HPD_2;
  230. break;
  231. case (1 << 16):
  232. hpd.hpd = RADEON_HPD_3;
  233. break;
  234. case (1 << 24):
  235. hpd.hpd = RADEON_HPD_4;
  236. break;
  237. case (1 << 26):
  238. hpd.hpd = RADEON_HPD_5;
  239. break;
  240. case (1 << 28):
  241. hpd.hpd = RADEON_HPD_6;
  242. break;
  243. default:
  244. hpd.hpd = RADEON_HPD_NONE;
  245. break;
  246. }
  247. } else
  248. hpd.hpd = RADEON_HPD_NONE;
  249. return hpd;
  250. }
  251. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  252. uint32_t supported_device,
  253. int *connector_type,
  254. struct radeon_i2c_bus_rec *i2c_bus,
  255. uint16_t *line_mux,
  256. struct radeon_hpd *hpd)
  257. {
  258. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  259. if ((dev->pdev->device == 0x791e) &&
  260. (dev->pdev->subsystem_vendor == 0x1043) &&
  261. (dev->pdev->subsystem_device == 0x826d)) {
  262. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  263. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  264. *connector_type = DRM_MODE_CONNECTOR_DVID;
  265. }
  266. /* Asrock RS600 board lists the DVI port as HDMI */
  267. if ((dev->pdev->device == 0x7941) &&
  268. (dev->pdev->subsystem_vendor == 0x1849) &&
  269. (dev->pdev->subsystem_device == 0x7941)) {
  270. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  271. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  272. *connector_type = DRM_MODE_CONNECTOR_DVID;
  273. }
  274. /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
  275. if ((dev->pdev->device == 0x796e) &&
  276. (dev->pdev->subsystem_vendor == 0x1462) &&
  277. (dev->pdev->subsystem_device == 0x7302)) {
  278. if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
  279. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  280. return false;
  281. }
  282. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  283. if ((dev->pdev->device == 0x7941) &&
  284. (dev->pdev->subsystem_vendor == 0x147b) &&
  285. (dev->pdev->subsystem_device == 0x2412)) {
  286. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  287. return false;
  288. }
  289. /* Falcon NW laptop lists vga ddc line for LVDS */
  290. if ((dev->pdev->device == 0x5653) &&
  291. (dev->pdev->subsystem_vendor == 0x1462) &&
  292. (dev->pdev->subsystem_device == 0x0291)) {
  293. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  294. i2c_bus->valid = false;
  295. *line_mux = 53;
  296. }
  297. }
  298. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  299. if ((dev->pdev->device == 0x7146) &&
  300. (dev->pdev->subsystem_vendor == 0x17af) &&
  301. (dev->pdev->subsystem_device == 0x2058)) {
  302. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  303. return false;
  304. }
  305. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  306. if ((dev->pdev->device == 0x7142) &&
  307. (dev->pdev->subsystem_vendor == 0x1458) &&
  308. (dev->pdev->subsystem_device == 0x2134)) {
  309. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  310. return false;
  311. }
  312. /* Funky macbooks */
  313. if ((dev->pdev->device == 0x71C5) &&
  314. (dev->pdev->subsystem_vendor == 0x106b) &&
  315. (dev->pdev->subsystem_device == 0x0080)) {
  316. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  317. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  318. return false;
  319. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  320. *line_mux = 0x90;
  321. }
  322. /* mac rv630, rv730, others */
  323. if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
  324. (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
  325. *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
  326. *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
  327. }
  328. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  329. if ((dev->pdev->device == 0x9598) &&
  330. (dev->pdev->subsystem_vendor == 0x1043) &&
  331. (dev->pdev->subsystem_device == 0x01da)) {
  332. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  333. *connector_type = DRM_MODE_CONNECTOR_DVII;
  334. }
  335. }
  336. /* ASUS HD 3600 board lists the DVI port as HDMI */
  337. if ((dev->pdev->device == 0x9598) &&
  338. (dev->pdev->subsystem_vendor == 0x1043) &&
  339. (dev->pdev->subsystem_device == 0x01e4)) {
  340. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  341. *connector_type = DRM_MODE_CONNECTOR_DVII;
  342. }
  343. }
  344. /* ASUS HD 3450 board lists the DVI port as HDMI */
  345. if ((dev->pdev->device == 0x95C5) &&
  346. (dev->pdev->subsystem_vendor == 0x1043) &&
  347. (dev->pdev->subsystem_device == 0x01e2)) {
  348. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  349. *connector_type = DRM_MODE_CONNECTOR_DVII;
  350. }
  351. }
  352. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  353. * HDMI + VGA reporting as HDMI
  354. */
  355. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  356. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  357. *connector_type = DRM_MODE_CONNECTOR_VGA;
  358. *line_mux = 0;
  359. }
  360. }
  361. /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
  362. * on the laptop and a DVI port on the docking station and
  363. * both share the same encoder, hpd pin, and ddc line.
  364. * So while the bios table is technically correct,
  365. * we drop the DVI port here since xrandr has no concept of
  366. * encoders and will try and drive both connectors
  367. * with different crtcs which isn't possible on the hardware
  368. * side and leaves no crtcs for LVDS or VGA.
  369. */
  370. if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
  371. (dev->pdev->subsystem_vendor == 0x1025) &&
  372. (dev->pdev->subsystem_device == 0x013c)) {
  373. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  374. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  375. /* actually it's a DVI-D port not DVI-I */
  376. *connector_type = DRM_MODE_CONNECTOR_DVID;
  377. return false;
  378. }
  379. }
  380. /* XFX Pine Group device rv730 reports no VGA DDC lines
  381. * even though they are wired up to record 0x93
  382. */
  383. if ((dev->pdev->device == 0x9498) &&
  384. (dev->pdev->subsystem_vendor == 0x1682) &&
  385. (dev->pdev->subsystem_device == 0x2452) &&
  386. (i2c_bus->valid == false) &&
  387. !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
  388. struct radeon_device *rdev = dev->dev_private;
  389. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  390. }
  391. /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
  392. if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
  393. (dev->pdev->subsystem_vendor == 0x1734) &&
  394. (dev->pdev->subsystem_device == 0x11bd)) {
  395. if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
  396. *connector_type = DRM_MODE_CONNECTOR_DVII;
  397. *line_mux = 0x3103;
  398. } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
  399. *connector_type = DRM_MODE_CONNECTOR_DVII;
  400. }
  401. }
  402. return true;
  403. }
  404. const int supported_devices_connector_convert[] = {
  405. DRM_MODE_CONNECTOR_Unknown,
  406. DRM_MODE_CONNECTOR_VGA,
  407. DRM_MODE_CONNECTOR_DVII,
  408. DRM_MODE_CONNECTOR_DVID,
  409. DRM_MODE_CONNECTOR_DVIA,
  410. DRM_MODE_CONNECTOR_SVIDEO,
  411. DRM_MODE_CONNECTOR_Composite,
  412. DRM_MODE_CONNECTOR_LVDS,
  413. DRM_MODE_CONNECTOR_Unknown,
  414. DRM_MODE_CONNECTOR_Unknown,
  415. DRM_MODE_CONNECTOR_HDMIA,
  416. DRM_MODE_CONNECTOR_HDMIB,
  417. DRM_MODE_CONNECTOR_Unknown,
  418. DRM_MODE_CONNECTOR_Unknown,
  419. DRM_MODE_CONNECTOR_9PinDIN,
  420. DRM_MODE_CONNECTOR_DisplayPort
  421. };
  422. const uint16_t supported_devices_connector_object_id_convert[] = {
  423. CONNECTOR_OBJECT_ID_NONE,
  424. CONNECTOR_OBJECT_ID_VGA,
  425. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  426. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  427. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  428. CONNECTOR_OBJECT_ID_COMPOSITE,
  429. CONNECTOR_OBJECT_ID_SVIDEO,
  430. CONNECTOR_OBJECT_ID_LVDS,
  431. CONNECTOR_OBJECT_ID_9PIN_DIN,
  432. CONNECTOR_OBJECT_ID_9PIN_DIN,
  433. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  434. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  435. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  436. CONNECTOR_OBJECT_ID_SVIDEO
  437. };
  438. const int object_connector_convert[] = {
  439. DRM_MODE_CONNECTOR_Unknown,
  440. DRM_MODE_CONNECTOR_DVII,
  441. DRM_MODE_CONNECTOR_DVII,
  442. DRM_MODE_CONNECTOR_DVID,
  443. DRM_MODE_CONNECTOR_DVID,
  444. DRM_MODE_CONNECTOR_VGA,
  445. DRM_MODE_CONNECTOR_Composite,
  446. DRM_MODE_CONNECTOR_SVIDEO,
  447. DRM_MODE_CONNECTOR_Unknown,
  448. DRM_MODE_CONNECTOR_Unknown,
  449. DRM_MODE_CONNECTOR_9PinDIN,
  450. DRM_MODE_CONNECTOR_Unknown,
  451. DRM_MODE_CONNECTOR_HDMIA,
  452. DRM_MODE_CONNECTOR_HDMIB,
  453. DRM_MODE_CONNECTOR_LVDS,
  454. DRM_MODE_CONNECTOR_9PinDIN,
  455. DRM_MODE_CONNECTOR_Unknown,
  456. DRM_MODE_CONNECTOR_Unknown,
  457. DRM_MODE_CONNECTOR_Unknown,
  458. DRM_MODE_CONNECTOR_DisplayPort,
  459. DRM_MODE_CONNECTOR_eDP,
  460. DRM_MODE_CONNECTOR_Unknown
  461. };
  462. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  463. {
  464. struct radeon_device *rdev = dev->dev_private;
  465. struct radeon_mode_info *mode_info = &rdev->mode_info;
  466. struct atom_context *ctx = mode_info->atom_context;
  467. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  468. u16 size, data_offset;
  469. u8 frev, crev;
  470. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  471. ATOM_ENCODER_OBJECT_TABLE *enc_obj;
  472. ATOM_OBJECT_TABLE *router_obj;
  473. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  474. ATOM_OBJECT_HEADER *obj_header;
  475. int i, j, k, path_size, device_support;
  476. int connector_type;
  477. u16 igp_lane_info, conn_id, connector_object_id;
  478. struct radeon_i2c_bus_rec ddc_bus;
  479. struct radeon_router router;
  480. struct radeon_gpio_rec gpio;
  481. struct radeon_hpd hpd;
  482. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  483. return false;
  484. if (crev < 2)
  485. return false;
  486. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  487. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  488. (ctx->bios + data_offset +
  489. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  490. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  491. (ctx->bios + data_offset +
  492. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  493. enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
  494. (ctx->bios + data_offset +
  495. le16_to_cpu(obj_header->usEncoderObjectTableOffset));
  496. router_obj = (ATOM_OBJECT_TABLE *)
  497. (ctx->bios + data_offset +
  498. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  499. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  500. path_size = 0;
  501. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  502. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  503. ATOM_DISPLAY_OBJECT_PATH *path;
  504. addr += path_size;
  505. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  506. path_size += le16_to_cpu(path->usSize);
  507. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  508. uint8_t con_obj_id, con_obj_num, con_obj_type;
  509. con_obj_id =
  510. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  511. >> OBJECT_ID_SHIFT;
  512. con_obj_num =
  513. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  514. >> ENUM_ID_SHIFT;
  515. con_obj_type =
  516. (le16_to_cpu(path->usConnObjectId) &
  517. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  518. /* TODO CV support */
  519. if (le16_to_cpu(path->usDeviceTag) ==
  520. ATOM_DEVICE_CV_SUPPORT)
  521. continue;
  522. /* IGP chips */
  523. if ((rdev->flags & RADEON_IS_IGP) &&
  524. (con_obj_id ==
  525. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  526. uint16_t igp_offset = 0;
  527. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  528. index =
  529. GetIndexIntoMasterTable(DATA,
  530. IntegratedSystemInfo);
  531. if (atom_parse_data_header(ctx, index, &size, &frev,
  532. &crev, &igp_offset)) {
  533. if (crev >= 2) {
  534. igp_obj =
  535. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  536. *) (ctx->bios + igp_offset);
  537. if (igp_obj) {
  538. uint32_t slot_config, ct;
  539. if (con_obj_num == 1)
  540. slot_config =
  541. igp_obj->
  542. ulDDISlot1Config;
  543. else
  544. slot_config =
  545. igp_obj->
  546. ulDDISlot2Config;
  547. ct = (slot_config >> 16) & 0xff;
  548. connector_type =
  549. object_connector_convert
  550. [ct];
  551. connector_object_id = ct;
  552. igp_lane_info =
  553. slot_config & 0xffff;
  554. } else
  555. continue;
  556. } else
  557. continue;
  558. } else {
  559. igp_lane_info = 0;
  560. connector_type =
  561. object_connector_convert[con_obj_id];
  562. connector_object_id = con_obj_id;
  563. }
  564. } else {
  565. igp_lane_info = 0;
  566. connector_type =
  567. object_connector_convert[con_obj_id];
  568. connector_object_id = con_obj_id;
  569. }
  570. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  571. continue;
  572. router.ddc_valid = false;
  573. router.cd_valid = false;
  574. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  575. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  576. grph_obj_id =
  577. (le16_to_cpu(path->usGraphicObjIds[j]) &
  578. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  579. grph_obj_num =
  580. (le16_to_cpu(path->usGraphicObjIds[j]) &
  581. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  582. grph_obj_type =
  583. (le16_to_cpu(path->usGraphicObjIds[j]) &
  584. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  585. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  586. for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
  587. u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
  588. if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
  589. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  590. (ctx->bios + data_offset +
  591. le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
  592. ATOM_ENCODER_CAP_RECORD *cap_record;
  593. u16 caps = 0;
  594. while (record->ucRecordSize > 0 &&
  595. record->ucRecordType > 0 &&
  596. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  597. switch (record->ucRecordType) {
  598. case ATOM_ENCODER_CAP_RECORD_TYPE:
  599. cap_record =(ATOM_ENCODER_CAP_RECORD *)
  600. record;
  601. caps = le16_to_cpu(cap_record->usEncoderCap);
  602. break;
  603. }
  604. record = (ATOM_COMMON_RECORD_HEADER *)
  605. ((char *)record + record->ucRecordSize);
  606. }
  607. radeon_add_atom_encoder(dev,
  608. encoder_obj,
  609. le16_to_cpu
  610. (path->
  611. usDeviceTag),
  612. caps);
  613. }
  614. }
  615. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  616. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  617. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
  618. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  619. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  620. (ctx->bios + data_offset +
  621. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  622. ATOM_I2C_RECORD *i2c_record;
  623. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  624. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  625. ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
  626. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  627. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  628. (ctx->bios + data_offset +
  629. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  630. u8 *num_dst_objs = (u8 *)
  631. ((u8 *)router_src_dst_table + 1 +
  632. (router_src_dst_table->ucNumberOfSrc * 2));
  633. u16 *dst_objs = (u16 *)(num_dst_objs + 1);
  634. int enum_id;
  635. router.router_id = router_obj_id;
  636. for (enum_id = 0; enum_id < (*num_dst_objs); enum_id++) {
  637. if (le16_to_cpu(path->usConnObjectId) ==
  638. le16_to_cpu(dst_objs[enum_id]))
  639. break;
  640. }
  641. while (record->ucRecordSize > 0 &&
  642. record->ucRecordType > 0 &&
  643. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  644. switch (record->ucRecordType) {
  645. case ATOM_I2C_RECORD_TYPE:
  646. i2c_record =
  647. (ATOM_I2C_RECORD *)
  648. record;
  649. i2c_config =
  650. (ATOM_I2C_ID_CONFIG_ACCESS *)
  651. &i2c_record->sucI2cId;
  652. router.i2c_info =
  653. radeon_lookup_i2c_gpio(rdev,
  654. i2c_config->
  655. ucAccess);
  656. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  657. break;
  658. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  659. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  660. record;
  661. router.ddc_valid = true;
  662. router.ddc_mux_type = ddc_path->ucMuxType;
  663. router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
  664. router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
  665. break;
  666. case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
  667. cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
  668. record;
  669. router.cd_valid = true;
  670. router.cd_mux_type = cd_path->ucMuxType;
  671. router.cd_mux_control_pin = cd_path->ucMuxControlPin;
  672. router.cd_mux_state = cd_path->ucMuxState[enum_id];
  673. break;
  674. }
  675. record = (ATOM_COMMON_RECORD_HEADER *)
  676. ((char *)record + record->ucRecordSize);
  677. }
  678. }
  679. }
  680. }
  681. }
  682. /* look up gpio for ddc, hpd */
  683. ddc_bus.valid = false;
  684. hpd.hpd = RADEON_HPD_NONE;
  685. if ((le16_to_cpu(path->usDeviceTag) &
  686. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  687. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  688. if (le16_to_cpu(path->usConnObjectId) ==
  689. le16_to_cpu(con_obj->asObjects[j].
  690. usObjectID)) {
  691. ATOM_COMMON_RECORD_HEADER
  692. *record =
  693. (ATOM_COMMON_RECORD_HEADER
  694. *)
  695. (ctx->bios + data_offset +
  696. le16_to_cpu(con_obj->
  697. asObjects[j].
  698. usRecordOffset));
  699. ATOM_I2C_RECORD *i2c_record;
  700. ATOM_HPD_INT_RECORD *hpd_record;
  701. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  702. while (record->ucRecordSize > 0 &&
  703. record->ucRecordType > 0 &&
  704. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  705. switch (record->ucRecordType) {
  706. case ATOM_I2C_RECORD_TYPE:
  707. i2c_record =
  708. (ATOM_I2C_RECORD *)
  709. record;
  710. i2c_config =
  711. (ATOM_I2C_ID_CONFIG_ACCESS *)
  712. &i2c_record->sucI2cId;
  713. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  714. i2c_config->
  715. ucAccess);
  716. break;
  717. case ATOM_HPD_INT_RECORD_TYPE:
  718. hpd_record =
  719. (ATOM_HPD_INT_RECORD *)
  720. record;
  721. gpio = radeon_lookup_gpio(rdev,
  722. hpd_record->ucHPDIntGPIOID);
  723. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  724. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  725. break;
  726. }
  727. record =
  728. (ATOM_COMMON_RECORD_HEADER
  729. *) ((char *)record
  730. +
  731. record->
  732. ucRecordSize);
  733. }
  734. break;
  735. }
  736. }
  737. }
  738. /* needed for aux chan transactions */
  739. ddc_bus.hpd = hpd.hpd;
  740. conn_id = le16_to_cpu(path->usConnObjectId);
  741. if (!radeon_atom_apply_quirks
  742. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  743. &ddc_bus, &conn_id, &hpd))
  744. continue;
  745. radeon_add_atom_connector(dev,
  746. conn_id,
  747. le16_to_cpu(path->
  748. usDeviceTag),
  749. connector_type, &ddc_bus,
  750. igp_lane_info,
  751. connector_object_id,
  752. &hpd,
  753. &router);
  754. }
  755. }
  756. radeon_link_encoder_connector(dev);
  757. return true;
  758. }
  759. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  760. int connector_type,
  761. uint16_t devices)
  762. {
  763. struct radeon_device *rdev = dev->dev_private;
  764. if (rdev->flags & RADEON_IS_IGP) {
  765. return supported_devices_connector_object_id_convert
  766. [connector_type];
  767. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  768. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  769. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  770. struct radeon_mode_info *mode_info = &rdev->mode_info;
  771. struct atom_context *ctx = mode_info->atom_context;
  772. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  773. uint16_t size, data_offset;
  774. uint8_t frev, crev;
  775. ATOM_XTMDS_INFO *xtmds;
  776. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  777. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  778. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  779. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  780. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  781. else
  782. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  783. } else {
  784. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  785. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  786. else
  787. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  788. }
  789. } else
  790. return supported_devices_connector_object_id_convert
  791. [connector_type];
  792. } else {
  793. return supported_devices_connector_object_id_convert
  794. [connector_type];
  795. }
  796. }
  797. struct bios_connector {
  798. bool valid;
  799. uint16_t line_mux;
  800. uint16_t devices;
  801. int connector_type;
  802. struct radeon_i2c_bus_rec ddc_bus;
  803. struct radeon_hpd hpd;
  804. };
  805. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  806. drm_device
  807. *dev)
  808. {
  809. struct radeon_device *rdev = dev->dev_private;
  810. struct radeon_mode_info *mode_info = &rdev->mode_info;
  811. struct atom_context *ctx = mode_info->atom_context;
  812. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  813. uint16_t size, data_offset;
  814. uint8_t frev, crev;
  815. uint16_t device_support;
  816. uint8_t dac;
  817. union atom_supported_devices *supported_devices;
  818. int i, j, max_device;
  819. struct bios_connector *bios_connectors;
  820. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  821. struct radeon_router router;
  822. router.ddc_valid = false;
  823. router.cd_valid = false;
  824. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  825. if (!bios_connectors)
  826. return false;
  827. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  828. &data_offset)) {
  829. kfree(bios_connectors);
  830. return false;
  831. }
  832. supported_devices =
  833. (union atom_supported_devices *)(ctx->bios + data_offset);
  834. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  835. if (frev > 1)
  836. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  837. else
  838. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  839. for (i = 0; i < max_device; i++) {
  840. ATOM_CONNECTOR_INFO_I2C ci =
  841. supported_devices->info.asConnInfo[i];
  842. bios_connectors[i].valid = false;
  843. if (!(device_support & (1 << i))) {
  844. continue;
  845. }
  846. if (i == ATOM_DEVICE_CV_INDEX) {
  847. DRM_DEBUG_KMS("Skipping Component Video\n");
  848. continue;
  849. }
  850. bios_connectors[i].connector_type =
  851. supported_devices_connector_convert[ci.sucConnectorInfo.
  852. sbfAccess.
  853. bfConnectorType];
  854. if (bios_connectors[i].connector_type ==
  855. DRM_MODE_CONNECTOR_Unknown)
  856. continue;
  857. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  858. bios_connectors[i].line_mux =
  859. ci.sucI2cId.ucAccess;
  860. /* give tv unique connector ids */
  861. if (i == ATOM_DEVICE_TV1_INDEX) {
  862. bios_connectors[i].ddc_bus.valid = false;
  863. bios_connectors[i].line_mux = 50;
  864. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  865. bios_connectors[i].ddc_bus.valid = false;
  866. bios_connectors[i].line_mux = 51;
  867. } else if (i == ATOM_DEVICE_CV_INDEX) {
  868. bios_connectors[i].ddc_bus.valid = false;
  869. bios_connectors[i].line_mux = 52;
  870. } else
  871. bios_connectors[i].ddc_bus =
  872. radeon_lookup_i2c_gpio(rdev,
  873. bios_connectors[i].line_mux);
  874. if ((crev > 1) && (frev > 1)) {
  875. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  876. switch (isb) {
  877. case 0x4:
  878. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  879. break;
  880. case 0xa:
  881. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  882. break;
  883. default:
  884. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  885. break;
  886. }
  887. } else {
  888. if (i == ATOM_DEVICE_DFP1_INDEX)
  889. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  890. else if (i == ATOM_DEVICE_DFP2_INDEX)
  891. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  892. else
  893. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  894. }
  895. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  896. * shared with a DVI port, we'll pick up the DVI connector when we
  897. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  898. */
  899. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  900. bios_connectors[i].connector_type =
  901. DRM_MODE_CONNECTOR_VGA;
  902. if (!radeon_atom_apply_quirks
  903. (dev, (1 << i), &bios_connectors[i].connector_type,
  904. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  905. &bios_connectors[i].hpd))
  906. continue;
  907. bios_connectors[i].valid = true;
  908. bios_connectors[i].devices = (1 << i);
  909. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  910. radeon_add_atom_encoder(dev,
  911. radeon_get_encoder_enum(dev,
  912. (1 << i),
  913. dac),
  914. (1 << i),
  915. 0);
  916. else
  917. radeon_add_legacy_encoder(dev,
  918. radeon_get_encoder_enum(dev,
  919. (1 << i),
  920. dac),
  921. (1 << i));
  922. }
  923. /* combine shared connectors */
  924. for (i = 0; i < max_device; i++) {
  925. if (bios_connectors[i].valid) {
  926. for (j = 0; j < max_device; j++) {
  927. if (bios_connectors[j].valid && (i != j)) {
  928. if (bios_connectors[i].line_mux ==
  929. bios_connectors[j].line_mux) {
  930. /* make sure not to combine LVDS */
  931. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  932. bios_connectors[i].line_mux = 53;
  933. bios_connectors[i].ddc_bus.valid = false;
  934. continue;
  935. }
  936. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  937. bios_connectors[j].line_mux = 53;
  938. bios_connectors[j].ddc_bus.valid = false;
  939. continue;
  940. }
  941. /* combine analog and digital for DVI-I */
  942. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  943. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  944. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  945. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  946. bios_connectors[i].devices |=
  947. bios_connectors[j].devices;
  948. bios_connectors[i].connector_type =
  949. DRM_MODE_CONNECTOR_DVII;
  950. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  951. bios_connectors[i].hpd =
  952. bios_connectors[j].hpd;
  953. bios_connectors[j].valid = false;
  954. }
  955. }
  956. }
  957. }
  958. }
  959. }
  960. /* add the connectors */
  961. for (i = 0; i < max_device; i++) {
  962. if (bios_connectors[i].valid) {
  963. uint16_t connector_object_id =
  964. atombios_get_connector_object_id(dev,
  965. bios_connectors[i].connector_type,
  966. bios_connectors[i].devices);
  967. radeon_add_atom_connector(dev,
  968. bios_connectors[i].line_mux,
  969. bios_connectors[i].devices,
  970. bios_connectors[i].
  971. connector_type,
  972. &bios_connectors[i].ddc_bus,
  973. 0,
  974. connector_object_id,
  975. &bios_connectors[i].hpd,
  976. &router);
  977. }
  978. }
  979. radeon_link_encoder_connector(dev);
  980. kfree(bios_connectors);
  981. return true;
  982. }
  983. union firmware_info {
  984. ATOM_FIRMWARE_INFO info;
  985. ATOM_FIRMWARE_INFO_V1_2 info_12;
  986. ATOM_FIRMWARE_INFO_V1_3 info_13;
  987. ATOM_FIRMWARE_INFO_V1_4 info_14;
  988. ATOM_FIRMWARE_INFO_V2_1 info_21;
  989. ATOM_FIRMWARE_INFO_V2_2 info_22;
  990. };
  991. bool radeon_atom_get_clock_info(struct drm_device *dev)
  992. {
  993. struct radeon_device *rdev = dev->dev_private;
  994. struct radeon_mode_info *mode_info = &rdev->mode_info;
  995. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  996. union firmware_info *firmware_info;
  997. uint8_t frev, crev;
  998. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  999. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  1000. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  1001. struct radeon_pll *spll = &rdev->clock.spll;
  1002. struct radeon_pll *mpll = &rdev->clock.mpll;
  1003. uint16_t data_offset;
  1004. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1005. &frev, &crev, &data_offset)) {
  1006. firmware_info =
  1007. (union firmware_info *)(mode_info->atom_context->bios +
  1008. data_offset);
  1009. /* pixel clocks */
  1010. p1pll->reference_freq =
  1011. le16_to_cpu(firmware_info->info.usReferenceClock);
  1012. p1pll->reference_div = 0;
  1013. if (crev < 2)
  1014. p1pll->pll_out_min =
  1015. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  1016. else
  1017. p1pll->pll_out_min =
  1018. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  1019. p1pll->pll_out_max =
  1020. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  1021. if (crev >= 4) {
  1022. p1pll->lcd_pll_out_min =
  1023. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  1024. if (p1pll->lcd_pll_out_min == 0)
  1025. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1026. p1pll->lcd_pll_out_max =
  1027. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  1028. if (p1pll->lcd_pll_out_max == 0)
  1029. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1030. } else {
  1031. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1032. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1033. }
  1034. if (p1pll->pll_out_min == 0) {
  1035. if (ASIC_IS_AVIVO(rdev))
  1036. p1pll->pll_out_min = 64800;
  1037. else
  1038. p1pll->pll_out_min = 20000;
  1039. }
  1040. p1pll->pll_in_min =
  1041. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  1042. p1pll->pll_in_max =
  1043. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  1044. *p2pll = *p1pll;
  1045. /* system clock */
  1046. if (ASIC_IS_DCE4(rdev))
  1047. spll->reference_freq =
  1048. le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
  1049. else
  1050. spll->reference_freq =
  1051. le16_to_cpu(firmware_info->info.usReferenceClock);
  1052. spll->reference_div = 0;
  1053. spll->pll_out_min =
  1054. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1055. spll->pll_out_max =
  1056. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1057. /* ??? */
  1058. if (spll->pll_out_min == 0) {
  1059. if (ASIC_IS_AVIVO(rdev))
  1060. spll->pll_out_min = 64800;
  1061. else
  1062. spll->pll_out_min = 20000;
  1063. }
  1064. spll->pll_in_min =
  1065. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1066. spll->pll_in_max =
  1067. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1068. /* memory clock */
  1069. if (ASIC_IS_DCE4(rdev))
  1070. mpll->reference_freq =
  1071. le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
  1072. else
  1073. mpll->reference_freq =
  1074. le16_to_cpu(firmware_info->info.usReferenceClock);
  1075. mpll->reference_div = 0;
  1076. mpll->pll_out_min =
  1077. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1078. mpll->pll_out_max =
  1079. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1080. /* ??? */
  1081. if (mpll->pll_out_min == 0) {
  1082. if (ASIC_IS_AVIVO(rdev))
  1083. mpll->pll_out_min = 64800;
  1084. else
  1085. mpll->pll_out_min = 20000;
  1086. }
  1087. mpll->pll_in_min =
  1088. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1089. mpll->pll_in_max =
  1090. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1091. rdev->clock.default_sclk =
  1092. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1093. rdev->clock.default_mclk =
  1094. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1095. if (ASIC_IS_DCE4(rdev)) {
  1096. rdev->clock.default_dispclk =
  1097. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1098. if (rdev->clock.default_dispclk == 0) {
  1099. if (ASIC_IS_DCE5(rdev))
  1100. rdev->clock.default_dispclk = 54000; /* 540 Mhz */
  1101. else
  1102. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1103. }
  1104. rdev->clock.dp_extclk =
  1105. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1106. rdev->clock.current_dispclk = rdev->clock.default_dispclk;
  1107. }
  1108. *dcpll = *p1pll;
  1109. rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
  1110. if (rdev->clock.max_pixel_clock == 0)
  1111. rdev->clock.max_pixel_clock = 40000;
  1112. /* not technically a clock, but... */
  1113. rdev->mode_info.firmware_flags =
  1114. le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
  1115. return true;
  1116. }
  1117. return false;
  1118. }
  1119. union igp_info {
  1120. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1121. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1122. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  1123. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
  1124. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
  1125. };
  1126. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1127. {
  1128. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1129. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1130. union igp_info *igp_info;
  1131. u8 frev, crev;
  1132. u16 data_offset;
  1133. /* sideport is AMD only */
  1134. if (rdev->family == CHIP_RS600)
  1135. return false;
  1136. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1137. &frev, &crev, &data_offset)) {
  1138. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1139. data_offset);
  1140. switch (crev) {
  1141. case 1:
  1142. if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
  1143. return true;
  1144. break;
  1145. case 2:
  1146. if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
  1147. return true;
  1148. break;
  1149. default:
  1150. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1151. break;
  1152. }
  1153. }
  1154. return false;
  1155. }
  1156. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1157. struct radeon_encoder_int_tmds *tmds)
  1158. {
  1159. struct drm_device *dev = encoder->base.dev;
  1160. struct radeon_device *rdev = dev->dev_private;
  1161. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1162. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1163. uint16_t data_offset;
  1164. struct _ATOM_TMDS_INFO *tmds_info;
  1165. uint8_t frev, crev;
  1166. uint16_t maxfreq;
  1167. int i;
  1168. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1169. &frev, &crev, &data_offset)) {
  1170. tmds_info =
  1171. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1172. data_offset);
  1173. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1174. for (i = 0; i < 4; i++) {
  1175. tmds->tmds_pll[i].freq =
  1176. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1177. tmds->tmds_pll[i].value =
  1178. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1179. tmds->tmds_pll[i].value |=
  1180. (tmds_info->asMiscInfo[i].
  1181. ucPLL_VCO_Gain & 0x3f) << 6;
  1182. tmds->tmds_pll[i].value |=
  1183. (tmds_info->asMiscInfo[i].
  1184. ucPLL_DutyCycle & 0xf) << 12;
  1185. tmds->tmds_pll[i].value |=
  1186. (tmds_info->asMiscInfo[i].
  1187. ucPLL_VoltageSwing & 0xf) << 16;
  1188. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1189. tmds->tmds_pll[i].freq,
  1190. tmds->tmds_pll[i].value);
  1191. if (maxfreq == tmds->tmds_pll[i].freq) {
  1192. tmds->tmds_pll[i].freq = 0xffffffff;
  1193. break;
  1194. }
  1195. }
  1196. return true;
  1197. }
  1198. return false;
  1199. }
  1200. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1201. struct radeon_atom_ss *ss,
  1202. int id)
  1203. {
  1204. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1205. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1206. uint16_t data_offset, size;
  1207. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1208. uint8_t frev, crev;
  1209. int i, num_indices;
  1210. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1211. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1212. &frev, &crev, &data_offset)) {
  1213. ss_info =
  1214. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1215. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1216. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1217. for (i = 0; i < num_indices; i++) {
  1218. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1219. ss->percentage =
  1220. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1221. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1222. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1223. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1224. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1225. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1226. return true;
  1227. }
  1228. }
  1229. }
  1230. return false;
  1231. }
  1232. static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
  1233. struct radeon_atom_ss *ss,
  1234. int id)
  1235. {
  1236. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1237. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1238. u16 data_offset, size;
  1239. union igp_info *igp_info;
  1240. u8 frev, crev;
  1241. u16 percentage = 0, rate = 0;
  1242. /* get any igp specific overrides */
  1243. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1244. &frev, &crev, &data_offset)) {
  1245. igp_info = (union igp_info *)
  1246. (mode_info->atom_context->bios + data_offset);
  1247. switch (crev) {
  1248. case 6:
  1249. switch (id) {
  1250. case ASIC_INTERNAL_SS_ON_TMDS:
  1251. percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
  1252. rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
  1253. break;
  1254. case ASIC_INTERNAL_SS_ON_HDMI:
  1255. percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
  1256. rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
  1257. break;
  1258. case ASIC_INTERNAL_SS_ON_LVDS:
  1259. percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
  1260. rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
  1261. break;
  1262. }
  1263. break;
  1264. case 7:
  1265. switch (id) {
  1266. case ASIC_INTERNAL_SS_ON_TMDS:
  1267. percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
  1268. rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
  1269. break;
  1270. case ASIC_INTERNAL_SS_ON_HDMI:
  1271. percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
  1272. rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
  1273. break;
  1274. case ASIC_INTERNAL_SS_ON_LVDS:
  1275. percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
  1276. rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
  1277. break;
  1278. }
  1279. break;
  1280. case 8:
  1281. switch (id) {
  1282. case ASIC_INTERNAL_SS_ON_TMDS:
  1283. percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage);
  1284. rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz);
  1285. break;
  1286. case ASIC_INTERNAL_SS_ON_HDMI:
  1287. percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage);
  1288. rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz);
  1289. break;
  1290. case ASIC_INTERNAL_SS_ON_LVDS:
  1291. percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage);
  1292. rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz);
  1293. break;
  1294. }
  1295. break;
  1296. default:
  1297. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1298. break;
  1299. }
  1300. if (percentage)
  1301. ss->percentage = percentage;
  1302. if (rate)
  1303. ss->rate = rate;
  1304. }
  1305. }
  1306. union asic_ss_info {
  1307. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1308. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1309. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1310. };
  1311. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1312. struct radeon_atom_ss *ss,
  1313. int id, u32 clock)
  1314. {
  1315. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1316. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1317. uint16_t data_offset, size;
  1318. union asic_ss_info *ss_info;
  1319. uint8_t frev, crev;
  1320. int i, num_indices;
  1321. if (id == ASIC_INTERNAL_MEMORY_SS) {
  1322. if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT))
  1323. return false;
  1324. }
  1325. if (id == ASIC_INTERNAL_ENGINE_SS) {
  1326. if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT))
  1327. return false;
  1328. }
  1329. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1330. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1331. &frev, &crev, &data_offset)) {
  1332. ss_info =
  1333. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1334. switch (frev) {
  1335. case 1:
  1336. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1337. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1338. for (i = 0; i < num_indices; i++) {
  1339. if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
  1340. (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
  1341. ss->percentage =
  1342. le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1343. ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1344. ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
  1345. return true;
  1346. }
  1347. }
  1348. break;
  1349. case 2:
  1350. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1351. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1352. for (i = 0; i < num_indices; i++) {
  1353. if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
  1354. (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
  1355. ss->percentage =
  1356. le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1357. ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1358. ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1359. if ((crev == 2) &&
  1360. ((id == ASIC_INTERNAL_ENGINE_SS) ||
  1361. (id == ASIC_INTERNAL_MEMORY_SS)))
  1362. ss->rate /= 100;
  1363. return true;
  1364. }
  1365. }
  1366. break;
  1367. case 3:
  1368. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1369. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1370. for (i = 0; i < num_indices; i++) {
  1371. if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
  1372. (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
  1373. ss->percentage =
  1374. le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1375. ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1376. ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1377. if ((id == ASIC_INTERNAL_ENGINE_SS) ||
  1378. (id == ASIC_INTERNAL_MEMORY_SS))
  1379. ss->rate /= 100;
  1380. if (rdev->flags & RADEON_IS_IGP)
  1381. radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
  1382. return true;
  1383. }
  1384. }
  1385. break;
  1386. default:
  1387. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1388. break;
  1389. }
  1390. }
  1391. return false;
  1392. }
  1393. union lvds_info {
  1394. struct _ATOM_LVDS_INFO info;
  1395. struct _ATOM_LVDS_INFO_V12 info_12;
  1396. };
  1397. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1398. radeon_encoder
  1399. *encoder)
  1400. {
  1401. struct drm_device *dev = encoder->base.dev;
  1402. struct radeon_device *rdev = dev->dev_private;
  1403. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1404. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1405. uint16_t data_offset, misc;
  1406. union lvds_info *lvds_info;
  1407. uint8_t frev, crev;
  1408. struct radeon_encoder_atom_dig *lvds = NULL;
  1409. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1410. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1411. &frev, &crev, &data_offset)) {
  1412. lvds_info =
  1413. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1414. lvds =
  1415. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1416. if (!lvds)
  1417. return NULL;
  1418. lvds->native_mode.clock =
  1419. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1420. lvds->native_mode.hdisplay =
  1421. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1422. lvds->native_mode.vdisplay =
  1423. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1424. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1425. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1426. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1427. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1428. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1429. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1430. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1431. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1432. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1433. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1434. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1435. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1436. lvds->panel_pwr_delay =
  1437. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1438. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1439. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1440. if (misc & ATOM_VSYNC_POLARITY)
  1441. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1442. if (misc & ATOM_HSYNC_POLARITY)
  1443. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1444. if (misc & ATOM_COMPOSITESYNC)
  1445. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1446. if (misc & ATOM_INTERLACE)
  1447. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1448. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1449. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1450. lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
  1451. lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
  1452. /* set crtc values */
  1453. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1454. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1455. encoder->native_mode = lvds->native_mode;
  1456. if (encoder_enum == 2)
  1457. lvds->linkb = true;
  1458. else
  1459. lvds->linkb = false;
  1460. /* parse the lcd record table */
  1461. if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
  1462. ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
  1463. ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
  1464. bool bad_record = false;
  1465. u8 *record;
  1466. if ((frev == 1) && (crev < 2))
  1467. /* absolute */
  1468. record = (u8 *)(mode_info->atom_context->bios +
  1469. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1470. else
  1471. /* relative */
  1472. record = (u8 *)(mode_info->atom_context->bios +
  1473. data_offset +
  1474. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1475. while (*record != ATOM_RECORD_END_TYPE) {
  1476. switch (*record) {
  1477. case LCD_MODE_PATCH_RECORD_MODE_TYPE:
  1478. record += sizeof(ATOM_PATCH_RECORD_MODE);
  1479. break;
  1480. case LCD_RTS_RECORD_TYPE:
  1481. record += sizeof(ATOM_LCD_RTS_RECORD);
  1482. break;
  1483. case LCD_CAP_RECORD_TYPE:
  1484. record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
  1485. break;
  1486. case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
  1487. fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
  1488. if (fake_edid_record->ucFakeEDIDLength) {
  1489. struct edid *edid;
  1490. int edid_size =
  1491. max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
  1492. edid = kmalloc(edid_size, GFP_KERNEL);
  1493. if (edid) {
  1494. memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
  1495. fake_edid_record->ucFakeEDIDLength);
  1496. if (drm_edid_is_valid(edid)) {
  1497. rdev->mode_info.bios_hardcoded_edid = edid;
  1498. rdev->mode_info.bios_hardcoded_edid_size = edid_size;
  1499. } else
  1500. kfree(edid);
  1501. }
  1502. }
  1503. record += fake_edid_record->ucFakeEDIDLength ?
  1504. fake_edid_record->ucFakeEDIDLength + 2 :
  1505. sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
  1506. break;
  1507. case LCD_PANEL_RESOLUTION_RECORD_TYPE:
  1508. panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
  1509. lvds->native_mode.width_mm = panel_res_record->usHSize;
  1510. lvds->native_mode.height_mm = panel_res_record->usVSize;
  1511. record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
  1512. break;
  1513. default:
  1514. DRM_ERROR("Bad LCD record %d\n", *record);
  1515. bad_record = true;
  1516. break;
  1517. }
  1518. if (bad_record)
  1519. break;
  1520. }
  1521. }
  1522. }
  1523. return lvds;
  1524. }
  1525. struct radeon_encoder_primary_dac *
  1526. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1527. {
  1528. struct drm_device *dev = encoder->base.dev;
  1529. struct radeon_device *rdev = dev->dev_private;
  1530. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1531. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1532. uint16_t data_offset;
  1533. struct _COMPASSIONATE_DATA *dac_info;
  1534. uint8_t frev, crev;
  1535. uint8_t bg, dac;
  1536. struct radeon_encoder_primary_dac *p_dac = NULL;
  1537. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1538. &frev, &crev, &data_offset)) {
  1539. dac_info = (struct _COMPASSIONATE_DATA *)
  1540. (mode_info->atom_context->bios + data_offset);
  1541. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1542. if (!p_dac)
  1543. return NULL;
  1544. bg = dac_info->ucDAC1_BG_Adjustment;
  1545. dac = dac_info->ucDAC1_DAC_Adjustment;
  1546. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1547. }
  1548. return p_dac;
  1549. }
  1550. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1551. struct drm_display_mode *mode)
  1552. {
  1553. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1554. ATOM_ANALOG_TV_INFO *tv_info;
  1555. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1556. ATOM_DTD_FORMAT *dtd_timings;
  1557. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1558. u8 frev, crev;
  1559. u16 data_offset, misc;
  1560. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1561. &frev, &crev, &data_offset))
  1562. return false;
  1563. switch (crev) {
  1564. case 1:
  1565. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1566. if (index >= MAX_SUPPORTED_TV_TIMING)
  1567. return false;
  1568. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1569. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1570. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1571. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1572. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1573. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1574. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1575. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1576. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1577. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1578. mode->flags = 0;
  1579. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1580. if (misc & ATOM_VSYNC_POLARITY)
  1581. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1582. if (misc & ATOM_HSYNC_POLARITY)
  1583. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1584. if (misc & ATOM_COMPOSITESYNC)
  1585. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1586. if (misc & ATOM_INTERLACE)
  1587. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1588. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1589. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1590. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1591. if (index == 1) {
  1592. /* PAL timings appear to have wrong values for totals */
  1593. mode->crtc_htotal -= 1;
  1594. mode->crtc_vtotal -= 1;
  1595. }
  1596. break;
  1597. case 2:
  1598. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1599. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1600. return false;
  1601. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1602. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1603. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1604. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1605. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1606. le16_to_cpu(dtd_timings->usHSyncOffset);
  1607. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1608. le16_to_cpu(dtd_timings->usHSyncWidth);
  1609. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1610. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1611. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1612. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1613. le16_to_cpu(dtd_timings->usVSyncOffset);
  1614. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1615. le16_to_cpu(dtd_timings->usVSyncWidth);
  1616. mode->flags = 0;
  1617. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1618. if (misc & ATOM_VSYNC_POLARITY)
  1619. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1620. if (misc & ATOM_HSYNC_POLARITY)
  1621. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1622. if (misc & ATOM_COMPOSITESYNC)
  1623. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1624. if (misc & ATOM_INTERLACE)
  1625. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1626. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1627. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1628. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1629. break;
  1630. }
  1631. return true;
  1632. }
  1633. enum radeon_tv_std
  1634. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1635. {
  1636. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1637. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1638. uint16_t data_offset;
  1639. uint8_t frev, crev;
  1640. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1641. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1642. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1643. &frev, &crev, &data_offset)) {
  1644. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1645. (mode_info->atom_context->bios + data_offset);
  1646. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1647. case ATOM_TV_NTSC:
  1648. tv_std = TV_STD_NTSC;
  1649. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1650. break;
  1651. case ATOM_TV_NTSCJ:
  1652. tv_std = TV_STD_NTSC_J;
  1653. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1654. break;
  1655. case ATOM_TV_PAL:
  1656. tv_std = TV_STD_PAL;
  1657. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1658. break;
  1659. case ATOM_TV_PALM:
  1660. tv_std = TV_STD_PAL_M;
  1661. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1662. break;
  1663. case ATOM_TV_PALN:
  1664. tv_std = TV_STD_PAL_N;
  1665. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1666. break;
  1667. case ATOM_TV_PALCN:
  1668. tv_std = TV_STD_PAL_CN;
  1669. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1670. break;
  1671. case ATOM_TV_PAL60:
  1672. tv_std = TV_STD_PAL_60;
  1673. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1674. break;
  1675. case ATOM_TV_SECAM:
  1676. tv_std = TV_STD_SECAM;
  1677. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1678. break;
  1679. default:
  1680. tv_std = TV_STD_NTSC;
  1681. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1682. break;
  1683. }
  1684. }
  1685. return tv_std;
  1686. }
  1687. struct radeon_encoder_tv_dac *
  1688. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1689. {
  1690. struct drm_device *dev = encoder->base.dev;
  1691. struct radeon_device *rdev = dev->dev_private;
  1692. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1693. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1694. uint16_t data_offset;
  1695. struct _COMPASSIONATE_DATA *dac_info;
  1696. uint8_t frev, crev;
  1697. uint8_t bg, dac;
  1698. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1699. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1700. &frev, &crev, &data_offset)) {
  1701. dac_info = (struct _COMPASSIONATE_DATA *)
  1702. (mode_info->atom_context->bios + data_offset);
  1703. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1704. if (!tv_dac)
  1705. return NULL;
  1706. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1707. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1708. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1709. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1710. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1711. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1712. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1713. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1714. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1715. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1716. }
  1717. return tv_dac;
  1718. }
  1719. static const char *thermal_controller_names[] = {
  1720. "NONE",
  1721. "lm63",
  1722. "adm1032",
  1723. "adm1030",
  1724. "max6649",
  1725. "lm64",
  1726. "f75375",
  1727. "asc7xxx",
  1728. };
  1729. static const char *pp_lib_thermal_controller_names[] = {
  1730. "NONE",
  1731. "lm63",
  1732. "adm1032",
  1733. "adm1030",
  1734. "max6649",
  1735. "lm64",
  1736. "f75375",
  1737. "RV6xx",
  1738. "RV770",
  1739. "adt7473",
  1740. "NONE",
  1741. "External GPIO",
  1742. "Evergreen",
  1743. "emc2103",
  1744. "Sumo",
  1745. "Northern Islands",
  1746. "Southern Islands",
  1747. "lm96163",
  1748. "Sea Islands",
  1749. };
  1750. union power_info {
  1751. struct _ATOM_POWERPLAY_INFO info;
  1752. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1753. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1754. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1755. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1756. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1757. };
  1758. union pplib_clock_info {
  1759. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1760. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1761. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1762. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1763. struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  1764. struct _ATOM_PPLIB_CI_CLOCK_INFO ci;
  1765. };
  1766. union pplib_power_state {
  1767. struct _ATOM_PPLIB_STATE v1;
  1768. struct _ATOM_PPLIB_STATE_V2 v2;
  1769. };
  1770. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1771. int state_index,
  1772. u32 misc, u32 misc2)
  1773. {
  1774. rdev->pm.power_state[state_index].misc = misc;
  1775. rdev->pm.power_state[state_index].misc2 = misc2;
  1776. /* order matters! */
  1777. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1778. rdev->pm.power_state[state_index].type =
  1779. POWER_STATE_TYPE_POWERSAVE;
  1780. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1781. rdev->pm.power_state[state_index].type =
  1782. POWER_STATE_TYPE_BATTERY;
  1783. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1784. rdev->pm.power_state[state_index].type =
  1785. POWER_STATE_TYPE_BATTERY;
  1786. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1787. rdev->pm.power_state[state_index].type =
  1788. POWER_STATE_TYPE_BALANCED;
  1789. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1790. rdev->pm.power_state[state_index].type =
  1791. POWER_STATE_TYPE_PERFORMANCE;
  1792. rdev->pm.power_state[state_index].flags &=
  1793. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1794. }
  1795. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1796. rdev->pm.power_state[state_index].type =
  1797. POWER_STATE_TYPE_BALANCED;
  1798. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1799. rdev->pm.power_state[state_index].type =
  1800. POWER_STATE_TYPE_DEFAULT;
  1801. rdev->pm.default_power_state_index = state_index;
  1802. rdev->pm.power_state[state_index].default_clock_mode =
  1803. &rdev->pm.power_state[state_index].clock_info[0];
  1804. } else if (state_index == 0) {
  1805. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1806. RADEON_PM_MODE_NO_DISPLAY;
  1807. }
  1808. }
  1809. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1810. {
  1811. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1812. u32 misc, misc2 = 0;
  1813. int num_modes = 0, i;
  1814. int state_index = 0;
  1815. struct radeon_i2c_bus_rec i2c_bus;
  1816. union power_info *power_info;
  1817. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1818. u16 data_offset;
  1819. u8 frev, crev;
  1820. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1821. &frev, &crev, &data_offset))
  1822. return state_index;
  1823. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1824. /* add the i2c bus for thermal/fan chip */
  1825. if ((power_info->info.ucOverdriveThermalController > 0) &&
  1826. (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
  1827. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1828. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1829. power_info->info.ucOverdriveControllerAddress >> 1);
  1830. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1831. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1832. if (rdev->pm.i2c_bus) {
  1833. struct i2c_board_info info = { };
  1834. const char *name = thermal_controller_names[power_info->info.
  1835. ucOverdriveThermalController];
  1836. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1837. strlcpy(info.type, name, sizeof(info.type));
  1838. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1839. }
  1840. }
  1841. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1842. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1843. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1844. if (num_modes == 0)
  1845. return state_index;
  1846. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
  1847. if (!rdev->pm.power_state)
  1848. return state_index;
  1849. /* last mode is usually default, array is low to high */
  1850. for (i = 0; i < num_modes; i++) {
  1851. rdev->pm.power_state[state_index].clock_info =
  1852. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  1853. if (!rdev->pm.power_state[state_index].clock_info)
  1854. return state_index;
  1855. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1856. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1857. switch (frev) {
  1858. case 1:
  1859. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1860. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1861. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1862. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1863. /* skip invalid modes */
  1864. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1865. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1866. continue;
  1867. rdev->pm.power_state[state_index].pcie_lanes =
  1868. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1869. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1870. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1871. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1872. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1873. VOLTAGE_GPIO;
  1874. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1875. radeon_lookup_gpio(rdev,
  1876. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1877. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1878. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1879. true;
  1880. else
  1881. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1882. false;
  1883. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1884. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1885. VOLTAGE_VDDC;
  1886. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1887. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1888. }
  1889. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1890. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1891. state_index++;
  1892. break;
  1893. case 2:
  1894. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1895. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1896. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1897. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1898. /* skip invalid modes */
  1899. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1900. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1901. continue;
  1902. rdev->pm.power_state[state_index].pcie_lanes =
  1903. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1904. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1905. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1906. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1907. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1908. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1909. VOLTAGE_GPIO;
  1910. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1911. radeon_lookup_gpio(rdev,
  1912. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1913. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1914. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1915. true;
  1916. else
  1917. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1918. false;
  1919. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1920. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1921. VOLTAGE_VDDC;
  1922. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1923. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1924. }
  1925. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1926. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1927. state_index++;
  1928. break;
  1929. case 3:
  1930. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1931. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1932. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1933. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1934. /* skip invalid modes */
  1935. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1936. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1937. continue;
  1938. rdev->pm.power_state[state_index].pcie_lanes =
  1939. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1940. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1941. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1942. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1943. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1944. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1945. VOLTAGE_GPIO;
  1946. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1947. radeon_lookup_gpio(rdev,
  1948. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1949. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1950. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1951. true;
  1952. else
  1953. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1954. false;
  1955. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1956. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1957. VOLTAGE_VDDC;
  1958. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1959. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1960. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1961. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1962. true;
  1963. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1964. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1965. }
  1966. }
  1967. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1968. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1969. state_index++;
  1970. break;
  1971. }
  1972. }
  1973. /* last mode is usually default */
  1974. if (rdev->pm.default_power_state_index == -1) {
  1975. rdev->pm.power_state[state_index - 1].type =
  1976. POWER_STATE_TYPE_DEFAULT;
  1977. rdev->pm.default_power_state_index = state_index - 1;
  1978. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1979. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1980. rdev->pm.power_state[state_index].flags &=
  1981. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1982. rdev->pm.power_state[state_index].misc = 0;
  1983. rdev->pm.power_state[state_index].misc2 = 0;
  1984. }
  1985. return state_index;
  1986. }
  1987. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  1988. ATOM_PPLIB_THERMALCONTROLLER *controller)
  1989. {
  1990. struct radeon_i2c_bus_rec i2c_bus;
  1991. /* add the i2c bus for thermal/fan chip */
  1992. if (controller->ucType > 0) {
  1993. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1994. DRM_INFO("Internal thermal controller %s fan control\n",
  1995. (controller->ucFanParameters &
  1996. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1997. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1998. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1999. DRM_INFO("Internal thermal controller %s fan control\n",
  2000. (controller->ucFanParameters &
  2001. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2002. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  2003. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  2004. DRM_INFO("Internal thermal controller %s fan control\n",
  2005. (controller->ucFanParameters &
  2006. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2007. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  2008. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  2009. DRM_INFO("Internal thermal controller %s fan control\n",
  2010. (controller->ucFanParameters &
  2011. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2012. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  2013. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  2014. DRM_INFO("Internal thermal controller %s fan control\n",
  2015. (controller->ucFanParameters &
  2016. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2017. rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
  2018. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
  2019. DRM_INFO("Internal thermal controller %s fan control\n",
  2020. (controller->ucFanParameters &
  2021. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2022. rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
  2023. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
  2024. DRM_INFO("Internal thermal controller %s fan control\n",
  2025. (controller->ucFanParameters &
  2026. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2027. rdev->pm.int_thermal_type = THERMAL_TYPE_CI;
  2028. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
  2029. DRM_INFO("Internal thermal controller %s fan control\n",
  2030. (controller->ucFanParameters &
  2031. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2032. rdev->pm.int_thermal_type = THERMAL_TYPE_KV;
  2033. } else if ((controller->ucType ==
  2034. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  2035. (controller->ucType ==
  2036. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
  2037. (controller->ucType ==
  2038. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
  2039. DRM_INFO("Special thermal controller config\n");
  2040. } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
  2041. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  2042. pp_lib_thermal_controller_names[controller->ucType],
  2043. controller->ucI2cAddress >> 1,
  2044. (controller->ucFanParameters &
  2045. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2046. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  2047. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2048. if (rdev->pm.i2c_bus) {
  2049. struct i2c_board_info info = { };
  2050. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  2051. info.addr = controller->ucI2cAddress >> 1;
  2052. strlcpy(info.type, name, sizeof(info.type));
  2053. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2054. }
  2055. } else {
  2056. DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
  2057. controller->ucType,
  2058. controller->ucI2cAddress >> 1,
  2059. (controller->ucFanParameters &
  2060. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2061. }
  2062. }
  2063. }
  2064. void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
  2065. u16 *vddc, u16 *vddci, u16 *mvdd)
  2066. {
  2067. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2068. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  2069. u8 frev, crev;
  2070. u16 data_offset;
  2071. union firmware_info *firmware_info;
  2072. *vddc = 0;
  2073. *vddci = 0;
  2074. *mvdd = 0;
  2075. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2076. &frev, &crev, &data_offset)) {
  2077. firmware_info =
  2078. (union firmware_info *)(mode_info->atom_context->bios +
  2079. data_offset);
  2080. *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
  2081. if ((frev == 2) && (crev >= 2)) {
  2082. *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
  2083. *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
  2084. }
  2085. }
  2086. }
  2087. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  2088. int state_index, int mode_index,
  2089. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  2090. {
  2091. int j;
  2092. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  2093. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  2094. u16 vddc, vddci, mvdd;
  2095. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
  2096. rdev->pm.power_state[state_index].misc = misc;
  2097. rdev->pm.power_state[state_index].misc2 = misc2;
  2098. rdev->pm.power_state[state_index].pcie_lanes =
  2099. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  2100. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  2101. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  2102. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  2103. rdev->pm.power_state[state_index].type =
  2104. POWER_STATE_TYPE_BATTERY;
  2105. break;
  2106. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  2107. rdev->pm.power_state[state_index].type =
  2108. POWER_STATE_TYPE_BALANCED;
  2109. break;
  2110. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  2111. rdev->pm.power_state[state_index].type =
  2112. POWER_STATE_TYPE_PERFORMANCE;
  2113. break;
  2114. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  2115. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  2116. rdev->pm.power_state[state_index].type =
  2117. POWER_STATE_TYPE_PERFORMANCE;
  2118. break;
  2119. }
  2120. rdev->pm.power_state[state_index].flags = 0;
  2121. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  2122. rdev->pm.power_state[state_index].flags |=
  2123. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2124. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2125. rdev->pm.power_state[state_index].type =
  2126. POWER_STATE_TYPE_DEFAULT;
  2127. rdev->pm.default_power_state_index = state_index;
  2128. rdev->pm.power_state[state_index].default_clock_mode =
  2129. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  2130. if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) {
  2131. /* NI chips post without MC ucode, so default clocks are strobe mode only */
  2132. rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
  2133. rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
  2134. rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
  2135. rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
  2136. } else {
  2137. u16 max_vddci = 0;
  2138. if (ASIC_IS_DCE4(rdev))
  2139. radeon_atom_get_max_voltage(rdev,
  2140. SET_VOLTAGE_TYPE_ASIC_VDDCI,
  2141. &max_vddci);
  2142. /* patch the table values with the default sclk/mclk from firmware info */
  2143. for (j = 0; j < mode_index; j++) {
  2144. rdev->pm.power_state[state_index].clock_info[j].mclk =
  2145. rdev->clock.default_mclk;
  2146. rdev->pm.power_state[state_index].clock_info[j].sclk =
  2147. rdev->clock.default_sclk;
  2148. if (vddc)
  2149. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  2150. vddc;
  2151. if (max_vddci)
  2152. rdev->pm.power_state[state_index].clock_info[j].voltage.vddci =
  2153. max_vddci;
  2154. }
  2155. }
  2156. }
  2157. }
  2158. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  2159. int state_index, int mode_index,
  2160. union pplib_clock_info *clock_info)
  2161. {
  2162. u32 sclk, mclk;
  2163. u16 vddc;
  2164. if (rdev->flags & RADEON_IS_IGP) {
  2165. if (rdev->family >= CHIP_PALM) {
  2166. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2167. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2168. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2169. } else {
  2170. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  2171. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  2172. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2173. }
  2174. } else if (rdev->family >= CHIP_BONAIRE) {
  2175. sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
  2176. sclk |= clock_info->ci.ucEngineClockHigh << 16;
  2177. mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
  2178. mclk |= clock_info->ci.ucMemoryClockHigh << 16;
  2179. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2180. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2181. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2182. VOLTAGE_NONE;
  2183. } else if (rdev->family >= CHIP_TAHITI) {
  2184. sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
  2185. sclk |= clock_info->si.ucEngineClockHigh << 16;
  2186. mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
  2187. mclk |= clock_info->si.ucMemoryClockHigh << 16;
  2188. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2189. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2190. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2191. VOLTAGE_SW;
  2192. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2193. le16_to_cpu(clock_info->si.usVDDC);
  2194. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2195. le16_to_cpu(clock_info->si.usVDDCI);
  2196. } else if (rdev->family >= CHIP_CEDAR) {
  2197. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  2198. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  2199. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  2200. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  2201. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2202. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2203. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2204. VOLTAGE_SW;
  2205. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2206. le16_to_cpu(clock_info->evergreen.usVDDC);
  2207. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2208. le16_to_cpu(clock_info->evergreen.usVDDCI);
  2209. } else {
  2210. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  2211. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  2212. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  2213. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  2214. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2215. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2216. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2217. VOLTAGE_SW;
  2218. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2219. le16_to_cpu(clock_info->r600.usVDDC);
  2220. }
  2221. /* patch up vddc if necessary */
  2222. switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
  2223. case ATOM_VIRTUAL_VOLTAGE_ID0:
  2224. case ATOM_VIRTUAL_VOLTAGE_ID1:
  2225. case ATOM_VIRTUAL_VOLTAGE_ID2:
  2226. case ATOM_VIRTUAL_VOLTAGE_ID3:
  2227. case ATOM_VIRTUAL_VOLTAGE_ID4:
  2228. case ATOM_VIRTUAL_VOLTAGE_ID5:
  2229. case ATOM_VIRTUAL_VOLTAGE_ID6:
  2230. case ATOM_VIRTUAL_VOLTAGE_ID7:
  2231. if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
  2232. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
  2233. &vddc) == 0)
  2234. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
  2235. break;
  2236. default:
  2237. break;
  2238. }
  2239. if (rdev->flags & RADEON_IS_IGP) {
  2240. /* skip invalid modes */
  2241. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  2242. return false;
  2243. } else {
  2244. /* skip invalid modes */
  2245. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  2246. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  2247. return false;
  2248. }
  2249. return true;
  2250. }
  2251. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  2252. {
  2253. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2254. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2255. union pplib_power_state *power_state;
  2256. int i, j;
  2257. int state_index = 0, mode_index = 0;
  2258. union pplib_clock_info *clock_info;
  2259. bool valid;
  2260. union power_info *power_info;
  2261. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2262. u16 data_offset;
  2263. u8 frev, crev;
  2264. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2265. &frev, &crev, &data_offset))
  2266. return state_index;
  2267. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2268. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2269. if (power_info->pplib.ucNumStates == 0)
  2270. return state_index;
  2271. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2272. power_info->pplib.ucNumStates, GFP_KERNEL);
  2273. if (!rdev->pm.power_state)
  2274. return state_index;
  2275. /* first mode is usually default, followed by low to high */
  2276. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  2277. mode_index = 0;
  2278. power_state = (union pplib_power_state *)
  2279. (mode_info->atom_context->bios + data_offset +
  2280. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  2281. i * power_info->pplib.ucStateEntrySize);
  2282. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2283. (mode_info->atom_context->bios + data_offset +
  2284. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  2285. (power_state->v1.ucNonClockStateIndex *
  2286. power_info->pplib.ucNonClockSize));
  2287. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2288. ((power_info->pplib.ucStateEntrySize - 1) ?
  2289. (power_info->pplib.ucStateEntrySize - 1) : 1),
  2290. GFP_KERNEL);
  2291. if (!rdev->pm.power_state[i].clock_info)
  2292. return state_index;
  2293. if (power_info->pplib.ucStateEntrySize - 1) {
  2294. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  2295. clock_info = (union pplib_clock_info *)
  2296. (mode_info->atom_context->bios + data_offset +
  2297. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  2298. (power_state->v1.ucClockStateIndices[j] *
  2299. power_info->pplib.ucClockInfoSize));
  2300. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2301. state_index, mode_index,
  2302. clock_info);
  2303. if (valid)
  2304. mode_index++;
  2305. }
  2306. } else {
  2307. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2308. rdev->clock.default_mclk;
  2309. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2310. rdev->clock.default_sclk;
  2311. mode_index++;
  2312. }
  2313. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2314. if (mode_index) {
  2315. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2316. non_clock_info);
  2317. state_index++;
  2318. }
  2319. }
  2320. /* if multiple clock modes, mark the lowest as no display */
  2321. for (i = 0; i < state_index; i++) {
  2322. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2323. rdev->pm.power_state[i].clock_info[0].flags |=
  2324. RADEON_PM_MODE_NO_DISPLAY;
  2325. }
  2326. /* first mode is usually default */
  2327. if (rdev->pm.default_power_state_index == -1) {
  2328. rdev->pm.power_state[0].type =
  2329. POWER_STATE_TYPE_DEFAULT;
  2330. rdev->pm.default_power_state_index = 0;
  2331. rdev->pm.power_state[0].default_clock_mode =
  2332. &rdev->pm.power_state[0].clock_info[0];
  2333. }
  2334. return state_index;
  2335. }
  2336. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2337. {
  2338. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2339. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2340. union pplib_power_state *power_state;
  2341. int i, j, non_clock_array_index, clock_array_index;
  2342. int state_index = 0, mode_index = 0;
  2343. union pplib_clock_info *clock_info;
  2344. struct _StateArray *state_array;
  2345. struct _ClockInfoArray *clock_info_array;
  2346. struct _NonClockInfoArray *non_clock_info_array;
  2347. bool valid;
  2348. union power_info *power_info;
  2349. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2350. u16 data_offset;
  2351. u8 frev, crev;
  2352. u8 *power_state_offset;
  2353. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2354. &frev, &crev, &data_offset))
  2355. return state_index;
  2356. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2357. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2358. state_array = (struct _StateArray *)
  2359. (mode_info->atom_context->bios + data_offset +
  2360. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  2361. clock_info_array = (struct _ClockInfoArray *)
  2362. (mode_info->atom_context->bios + data_offset +
  2363. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  2364. non_clock_info_array = (struct _NonClockInfoArray *)
  2365. (mode_info->atom_context->bios + data_offset +
  2366. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  2367. if (state_array->ucNumEntries == 0)
  2368. return state_index;
  2369. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2370. state_array->ucNumEntries, GFP_KERNEL);
  2371. if (!rdev->pm.power_state)
  2372. return state_index;
  2373. power_state_offset = (u8 *)state_array->states;
  2374. for (i = 0; i < state_array->ucNumEntries; i++) {
  2375. mode_index = 0;
  2376. power_state = (union pplib_power_state *)power_state_offset;
  2377. non_clock_array_index = power_state->v2.nonClockInfoIndex;
  2378. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2379. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2380. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2381. (power_state->v2.ucNumDPMLevels ?
  2382. power_state->v2.ucNumDPMLevels : 1),
  2383. GFP_KERNEL);
  2384. if (!rdev->pm.power_state[i].clock_info)
  2385. return state_index;
  2386. if (power_state->v2.ucNumDPMLevels) {
  2387. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2388. clock_array_index = power_state->v2.clockInfoIndex[j];
  2389. clock_info = (union pplib_clock_info *)
  2390. &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
  2391. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2392. state_index, mode_index,
  2393. clock_info);
  2394. if (valid)
  2395. mode_index++;
  2396. }
  2397. } else {
  2398. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2399. rdev->clock.default_mclk;
  2400. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2401. rdev->clock.default_sclk;
  2402. mode_index++;
  2403. }
  2404. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2405. if (mode_index) {
  2406. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2407. non_clock_info);
  2408. state_index++;
  2409. }
  2410. power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
  2411. }
  2412. /* if multiple clock modes, mark the lowest as no display */
  2413. for (i = 0; i < state_index; i++) {
  2414. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2415. rdev->pm.power_state[i].clock_info[0].flags |=
  2416. RADEON_PM_MODE_NO_DISPLAY;
  2417. }
  2418. /* first mode is usually default */
  2419. if (rdev->pm.default_power_state_index == -1) {
  2420. rdev->pm.power_state[0].type =
  2421. POWER_STATE_TYPE_DEFAULT;
  2422. rdev->pm.default_power_state_index = 0;
  2423. rdev->pm.power_state[0].default_clock_mode =
  2424. &rdev->pm.power_state[0].clock_info[0];
  2425. }
  2426. return state_index;
  2427. }
  2428. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2429. {
  2430. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2431. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2432. u16 data_offset;
  2433. u8 frev, crev;
  2434. int state_index = 0;
  2435. rdev->pm.default_power_state_index = -1;
  2436. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2437. &frev, &crev, &data_offset)) {
  2438. switch (frev) {
  2439. case 1:
  2440. case 2:
  2441. case 3:
  2442. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2443. break;
  2444. case 4:
  2445. case 5:
  2446. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2447. break;
  2448. case 6:
  2449. state_index = radeon_atombios_parse_power_table_6(rdev);
  2450. break;
  2451. default:
  2452. break;
  2453. }
  2454. }
  2455. if (state_index == 0) {
  2456. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
  2457. if (rdev->pm.power_state) {
  2458. rdev->pm.power_state[0].clock_info =
  2459. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2460. if (rdev->pm.power_state[0].clock_info) {
  2461. /* add the default mode */
  2462. rdev->pm.power_state[state_index].type =
  2463. POWER_STATE_TYPE_DEFAULT;
  2464. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2465. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2466. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2467. rdev->pm.power_state[state_index].default_clock_mode =
  2468. &rdev->pm.power_state[state_index].clock_info[0];
  2469. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2470. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2471. rdev->pm.default_power_state_index = state_index;
  2472. rdev->pm.power_state[state_index].flags = 0;
  2473. state_index++;
  2474. }
  2475. }
  2476. }
  2477. rdev->pm.num_power_states = state_index;
  2478. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2479. rdev->pm.current_clock_mode_index = 0;
  2480. if (rdev->pm.default_power_state_index >= 0)
  2481. rdev->pm.current_vddc =
  2482. rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2483. else
  2484. rdev->pm.current_vddc = 0;
  2485. }
  2486. union get_clock_dividers {
  2487. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
  2488. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
  2489. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
  2490. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
  2491. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
  2492. struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
  2493. struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
  2494. };
  2495. int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
  2496. u8 clock_type,
  2497. u32 clock,
  2498. bool strobe_mode,
  2499. struct atom_clock_dividers *dividers)
  2500. {
  2501. union get_clock_dividers args;
  2502. int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
  2503. u8 frev, crev;
  2504. memset(&args, 0, sizeof(args));
  2505. memset(dividers, 0, sizeof(struct atom_clock_dividers));
  2506. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2507. return -EINVAL;
  2508. switch (crev) {
  2509. case 1:
  2510. /* r4xx, r5xx */
  2511. args.v1.ucAction = clock_type;
  2512. args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */
  2513. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2514. dividers->post_div = args.v1.ucPostDiv;
  2515. dividers->fb_div = args.v1.ucFbDiv;
  2516. dividers->enable_post_div = true;
  2517. break;
  2518. case 2:
  2519. case 3:
  2520. case 5:
  2521. /* r6xx, r7xx, evergreen, ni, si */
  2522. if (rdev->family <= CHIP_RV770) {
  2523. args.v2.ucAction = clock_type;
  2524. args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */
  2525. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2526. dividers->post_div = args.v2.ucPostDiv;
  2527. dividers->fb_div = le16_to_cpu(args.v2.usFbDiv);
  2528. dividers->ref_div = args.v2.ucAction;
  2529. if (rdev->family == CHIP_RV770) {
  2530. dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ?
  2531. true : false;
  2532. dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0;
  2533. } else
  2534. dividers->enable_post_div = (dividers->fb_div & 1) ? true : false;
  2535. } else {
  2536. if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
  2537. args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
  2538. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2539. dividers->post_div = args.v3.ucPostDiv;
  2540. dividers->enable_post_div = (args.v3.ucCntlFlag &
  2541. ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
  2542. dividers->enable_dithen = (args.v3.ucCntlFlag &
  2543. ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
  2544. dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
  2545. dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
  2546. dividers->ref_div = args.v3.ucRefDiv;
  2547. dividers->vco_mode = (args.v3.ucCntlFlag &
  2548. ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
  2549. } else {
  2550. /* for SI we use ComputeMemoryClockParam for memory plls */
  2551. if (rdev->family >= CHIP_TAHITI)
  2552. return -EINVAL;
  2553. args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
  2554. if (strobe_mode)
  2555. args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
  2556. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2557. dividers->post_div = args.v5.ucPostDiv;
  2558. dividers->enable_post_div = (args.v5.ucCntlFlag &
  2559. ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
  2560. dividers->enable_dithen = (args.v5.ucCntlFlag &
  2561. ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
  2562. dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
  2563. dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
  2564. dividers->ref_div = args.v5.ucRefDiv;
  2565. dividers->vco_mode = (args.v5.ucCntlFlag &
  2566. ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
  2567. }
  2568. }
  2569. break;
  2570. case 4:
  2571. /* fusion */
  2572. args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
  2573. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2574. dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
  2575. dividers->real_clock = le32_to_cpu(args.v4.ulClock);
  2576. break;
  2577. case 6:
  2578. /* CI */
  2579. /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
  2580. args.v6_in.ulClock.ulComputeClockFlag = clock_type;
  2581. args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
  2582. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2583. dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
  2584. dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
  2585. dividers->ref_div = args.v6_out.ucPllRefDiv;
  2586. dividers->post_div = args.v6_out.ucPllPostDiv;
  2587. dividers->flags = args.v6_out.ucPllCntlFlag;
  2588. dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
  2589. dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
  2590. break;
  2591. default:
  2592. return -EINVAL;
  2593. }
  2594. return 0;
  2595. }
  2596. int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
  2597. u32 clock,
  2598. bool strobe_mode,
  2599. struct atom_mpll_param *mpll_param)
  2600. {
  2601. COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
  2602. int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
  2603. u8 frev, crev;
  2604. memset(&args, 0, sizeof(args));
  2605. memset(mpll_param, 0, sizeof(struct atom_mpll_param));
  2606. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2607. return -EINVAL;
  2608. switch (frev) {
  2609. case 2:
  2610. switch (crev) {
  2611. case 1:
  2612. /* SI */
  2613. args.ulClock = cpu_to_le32(clock); /* 10 khz */
  2614. args.ucInputFlag = 0;
  2615. if (strobe_mode)
  2616. args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
  2617. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2618. mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
  2619. mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
  2620. mpll_param->post_div = args.ucPostDiv;
  2621. mpll_param->dll_speed = args.ucDllSpeed;
  2622. mpll_param->bwcntl = args.ucBWCntl;
  2623. mpll_param->vco_mode =
  2624. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK) ? 1 : 0;
  2625. mpll_param->yclk_sel =
  2626. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
  2627. mpll_param->qdr =
  2628. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
  2629. mpll_param->half_rate =
  2630. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
  2631. break;
  2632. default:
  2633. return -EINVAL;
  2634. }
  2635. break;
  2636. default:
  2637. return -EINVAL;
  2638. }
  2639. return 0;
  2640. }
  2641. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2642. {
  2643. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2644. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2645. args.ucEnable = enable;
  2646. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2647. }
  2648. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2649. {
  2650. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2651. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2652. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2653. return le32_to_cpu(args.ulReturnEngineClock);
  2654. }
  2655. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2656. {
  2657. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2658. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2659. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2660. return le32_to_cpu(args.ulReturnMemoryClock);
  2661. }
  2662. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2663. uint32_t eng_clock)
  2664. {
  2665. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2666. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2667. args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
  2668. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2669. }
  2670. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2671. uint32_t mem_clock)
  2672. {
  2673. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2674. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2675. if (rdev->flags & RADEON_IS_IGP)
  2676. return;
  2677. args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
  2678. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2679. }
  2680. void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
  2681. u32 eng_clock, u32 mem_clock)
  2682. {
  2683. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2684. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2685. u32 tmp;
  2686. memset(&args, 0, sizeof(args));
  2687. tmp = eng_clock & SET_CLOCK_FREQ_MASK;
  2688. tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
  2689. args.ulTargetEngineClock = cpu_to_le32(tmp);
  2690. if (mem_clock)
  2691. args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
  2692. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2693. }
  2694. void radeon_atom_update_memory_dll(struct radeon_device *rdev,
  2695. u32 mem_clock)
  2696. {
  2697. u32 args;
  2698. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2699. args = cpu_to_le32(mem_clock); /* 10 khz */
  2700. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2701. }
  2702. void radeon_atom_set_ac_timing(struct radeon_device *rdev,
  2703. u32 mem_clock)
  2704. {
  2705. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2706. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2707. u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24);
  2708. args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */
  2709. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2710. }
  2711. union set_voltage {
  2712. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2713. struct _SET_VOLTAGE_PARAMETERS v1;
  2714. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2715. struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
  2716. };
  2717. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
  2718. {
  2719. union set_voltage args;
  2720. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2721. u8 frev, crev, volt_index = voltage_level;
  2722. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2723. return;
  2724. /* 0xff01 is a flag rather then an actual voltage */
  2725. if (voltage_level == 0xff01)
  2726. return;
  2727. switch (crev) {
  2728. case 1:
  2729. args.v1.ucVoltageType = voltage_type;
  2730. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2731. args.v1.ucVoltageIndex = volt_index;
  2732. break;
  2733. case 2:
  2734. args.v2.ucVoltageType = voltage_type;
  2735. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2736. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2737. break;
  2738. case 3:
  2739. args.v3.ucVoltageType = voltage_type;
  2740. args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
  2741. args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
  2742. break;
  2743. default:
  2744. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2745. return;
  2746. }
  2747. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2748. }
  2749. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  2750. u16 voltage_id, u16 *voltage)
  2751. {
  2752. union set_voltage args;
  2753. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2754. u8 frev, crev;
  2755. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2756. return -EINVAL;
  2757. switch (crev) {
  2758. case 1:
  2759. return -EINVAL;
  2760. case 2:
  2761. args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
  2762. args.v2.ucVoltageMode = 0;
  2763. args.v2.usVoltageLevel = 0;
  2764. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2765. *voltage = le16_to_cpu(args.v2.usVoltageLevel);
  2766. break;
  2767. case 3:
  2768. args.v3.ucVoltageType = voltage_type;
  2769. args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
  2770. args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
  2771. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2772. *voltage = le16_to_cpu(args.v3.usVoltageLevel);
  2773. break;
  2774. default:
  2775. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2776. return -EINVAL;
  2777. }
  2778. return 0;
  2779. }
  2780. int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
  2781. u16 *voltage,
  2782. u16 leakage_idx)
  2783. {
  2784. return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
  2785. }
  2786. int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
  2787. u16 *leakage_id)
  2788. {
  2789. union set_voltage args;
  2790. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2791. u8 frev, crev;
  2792. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2793. return -EINVAL;
  2794. switch (crev) {
  2795. case 3:
  2796. case 4:
  2797. args.v3.ucVoltageType = 0;
  2798. args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
  2799. args.v3.usVoltageLevel = 0;
  2800. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2801. *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
  2802. break;
  2803. default:
  2804. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2805. return -EINVAL;
  2806. }
  2807. return 0;
  2808. }
  2809. int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
  2810. u16 *vddc, u16 *vddci,
  2811. u16 virtual_voltage_id,
  2812. u16 vbios_voltage_id)
  2813. {
  2814. int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
  2815. u8 frev, crev;
  2816. u16 data_offset, size;
  2817. int i, j;
  2818. ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
  2819. u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
  2820. *vddc = 0;
  2821. *vddci = 0;
  2822. if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  2823. &frev, &crev, &data_offset))
  2824. return -EINVAL;
  2825. profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
  2826. (rdev->mode_info.atom_context->bios + data_offset);
  2827. switch (frev) {
  2828. case 1:
  2829. return -EINVAL;
  2830. case 2:
  2831. switch (crev) {
  2832. case 1:
  2833. if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
  2834. return -EINVAL;
  2835. leakage_bin = (u16 *)
  2836. (rdev->mode_info.atom_context->bios + data_offset +
  2837. le16_to_cpu(profile->usLeakageBinArrayOffset));
  2838. vddc_id_buf = (u16 *)
  2839. (rdev->mode_info.atom_context->bios + data_offset +
  2840. le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
  2841. vddc_buf = (u16 *)
  2842. (rdev->mode_info.atom_context->bios + data_offset +
  2843. le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
  2844. vddci_id_buf = (u16 *)
  2845. (rdev->mode_info.atom_context->bios + data_offset +
  2846. le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
  2847. vddci_buf = (u16 *)
  2848. (rdev->mode_info.atom_context->bios + data_offset +
  2849. le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
  2850. if (profile->ucElbVDDC_Num > 0) {
  2851. for (i = 0; i < profile->ucElbVDDC_Num; i++) {
  2852. if (vddc_id_buf[i] == virtual_voltage_id) {
  2853. for (j = 0; j < profile->ucLeakageBinNum; j++) {
  2854. if (vbios_voltage_id <= leakage_bin[j]) {
  2855. *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
  2856. break;
  2857. }
  2858. }
  2859. break;
  2860. }
  2861. }
  2862. }
  2863. if (profile->ucElbVDDCI_Num > 0) {
  2864. for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
  2865. if (vddci_id_buf[i] == virtual_voltage_id) {
  2866. for (j = 0; j < profile->ucLeakageBinNum; j++) {
  2867. if (vbios_voltage_id <= leakage_bin[j]) {
  2868. *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
  2869. break;
  2870. }
  2871. }
  2872. break;
  2873. }
  2874. }
  2875. }
  2876. break;
  2877. default:
  2878. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2879. return -EINVAL;
  2880. }
  2881. break;
  2882. default:
  2883. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2884. return -EINVAL;
  2885. }
  2886. return 0;
  2887. }
  2888. int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
  2889. u16 voltage_level, u8 voltage_type,
  2890. u32 *gpio_value, u32 *gpio_mask)
  2891. {
  2892. union set_voltage args;
  2893. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2894. u8 frev, crev;
  2895. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2896. return -EINVAL;
  2897. switch (crev) {
  2898. case 1:
  2899. return -EINVAL;
  2900. case 2:
  2901. args.v2.ucVoltageType = voltage_type;
  2902. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK;
  2903. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2904. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2905. *gpio_mask = le32_to_cpu(*(u32 *)&args.v2);
  2906. args.v2.ucVoltageType = voltage_type;
  2907. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL;
  2908. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2909. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2910. *gpio_value = le32_to_cpu(*(u32 *)&args.v2);
  2911. break;
  2912. default:
  2913. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2914. return -EINVAL;
  2915. }
  2916. return 0;
  2917. }
  2918. union voltage_object_info {
  2919. struct _ATOM_VOLTAGE_OBJECT_INFO v1;
  2920. struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
  2921. struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
  2922. };
  2923. union voltage_object {
  2924. struct _ATOM_VOLTAGE_OBJECT v1;
  2925. struct _ATOM_VOLTAGE_OBJECT_V2 v2;
  2926. union _ATOM_VOLTAGE_OBJECT_V3 v3;
  2927. };
  2928. static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1,
  2929. u8 voltage_type)
  2930. {
  2931. u32 size = le16_to_cpu(v1->sHeader.usStructureSize);
  2932. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]);
  2933. u8 *start = (u8 *)v1;
  2934. while (offset < size) {
  2935. ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset);
  2936. if (vo->ucVoltageType == voltage_type)
  2937. return vo;
  2938. offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) +
  2939. vo->asFormula.ucNumOfVoltageEntries;
  2940. }
  2941. return NULL;
  2942. }
  2943. static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2,
  2944. u8 voltage_type)
  2945. {
  2946. u32 size = le16_to_cpu(v2->sHeader.usStructureSize);
  2947. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]);
  2948. u8 *start = (u8*)v2;
  2949. while (offset < size) {
  2950. ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset);
  2951. if (vo->ucVoltageType == voltage_type)
  2952. return vo;
  2953. offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) +
  2954. (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY));
  2955. }
  2956. return NULL;
  2957. }
  2958. static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
  2959. u8 voltage_type, u8 voltage_mode)
  2960. {
  2961. u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
  2962. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
  2963. u8 *start = (u8*)v3;
  2964. while (offset < size) {
  2965. ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
  2966. if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
  2967. (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
  2968. return vo;
  2969. offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
  2970. }
  2971. return NULL;
  2972. }
  2973. bool
  2974. radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
  2975. u8 voltage_type, u8 voltage_mode)
  2976. {
  2977. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  2978. u8 frev, crev;
  2979. u16 data_offset, size;
  2980. union voltage_object_info *voltage_info;
  2981. union voltage_object *voltage_object = NULL;
  2982. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  2983. &frev, &crev, &data_offset)) {
  2984. voltage_info = (union voltage_object_info *)
  2985. (rdev->mode_info.atom_context->bios + data_offset);
  2986. switch (frev) {
  2987. case 1:
  2988. case 2:
  2989. switch (crev) {
  2990. case 1:
  2991. voltage_object = (union voltage_object *)
  2992. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  2993. if (voltage_object &&
  2994. (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
  2995. return true;
  2996. break;
  2997. case 2:
  2998. voltage_object = (union voltage_object *)
  2999. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3000. if (voltage_object &&
  3001. (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
  3002. return true;
  3003. break;
  3004. default:
  3005. DRM_ERROR("unknown voltage object table\n");
  3006. return false;
  3007. }
  3008. break;
  3009. case 3:
  3010. switch (crev) {
  3011. case 1:
  3012. if (atom_lookup_voltage_object_v3(&voltage_info->v3,
  3013. voltage_type, voltage_mode))
  3014. return true;
  3015. break;
  3016. default:
  3017. DRM_ERROR("unknown voltage object table\n");
  3018. return false;
  3019. }
  3020. break;
  3021. default:
  3022. DRM_ERROR("unknown voltage object table\n");
  3023. return false;
  3024. }
  3025. }
  3026. return false;
  3027. }
  3028. int radeon_atom_get_max_voltage(struct radeon_device *rdev,
  3029. u8 voltage_type, u16 *max_voltage)
  3030. {
  3031. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3032. u8 frev, crev;
  3033. u16 data_offset, size;
  3034. union voltage_object_info *voltage_info;
  3035. union voltage_object *voltage_object = NULL;
  3036. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3037. &frev, &crev, &data_offset)) {
  3038. voltage_info = (union voltage_object_info *)
  3039. (rdev->mode_info.atom_context->bios + data_offset);
  3040. switch (crev) {
  3041. case 1:
  3042. voltage_object = (union voltage_object *)
  3043. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3044. if (voltage_object) {
  3045. ATOM_VOLTAGE_FORMULA *formula =
  3046. &voltage_object->v1.asFormula;
  3047. if (formula->ucFlag & 1)
  3048. *max_voltage =
  3049. le16_to_cpu(formula->usVoltageBaseLevel) +
  3050. formula->ucNumOfVoltageEntries / 2 *
  3051. le16_to_cpu(formula->usVoltageStep);
  3052. else
  3053. *max_voltage =
  3054. le16_to_cpu(formula->usVoltageBaseLevel) +
  3055. (formula->ucNumOfVoltageEntries - 1) *
  3056. le16_to_cpu(formula->usVoltageStep);
  3057. return 0;
  3058. }
  3059. break;
  3060. case 2:
  3061. voltage_object = (union voltage_object *)
  3062. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3063. if (voltage_object) {
  3064. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3065. &voltage_object->v2.asFormula;
  3066. if (formula->ucNumOfVoltageEntries) {
  3067. *max_voltage =
  3068. le16_to_cpu(formula->asVIDAdjustEntries[
  3069. formula->ucNumOfVoltageEntries - 1
  3070. ].usVoltageValue);
  3071. return 0;
  3072. }
  3073. }
  3074. break;
  3075. default:
  3076. DRM_ERROR("unknown voltage object table\n");
  3077. return -EINVAL;
  3078. }
  3079. }
  3080. return -EINVAL;
  3081. }
  3082. int radeon_atom_get_min_voltage(struct radeon_device *rdev,
  3083. u8 voltage_type, u16 *min_voltage)
  3084. {
  3085. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3086. u8 frev, crev;
  3087. u16 data_offset, size;
  3088. union voltage_object_info *voltage_info;
  3089. union voltage_object *voltage_object = NULL;
  3090. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3091. &frev, &crev, &data_offset)) {
  3092. voltage_info = (union voltage_object_info *)
  3093. (rdev->mode_info.atom_context->bios + data_offset);
  3094. switch (crev) {
  3095. case 1:
  3096. voltage_object = (union voltage_object *)
  3097. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3098. if (voltage_object) {
  3099. ATOM_VOLTAGE_FORMULA *formula =
  3100. &voltage_object->v1.asFormula;
  3101. *min_voltage =
  3102. le16_to_cpu(formula->usVoltageBaseLevel);
  3103. return 0;
  3104. }
  3105. break;
  3106. case 2:
  3107. voltage_object = (union voltage_object *)
  3108. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3109. if (voltage_object) {
  3110. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3111. &voltage_object->v2.asFormula;
  3112. if (formula->ucNumOfVoltageEntries) {
  3113. *min_voltage =
  3114. le16_to_cpu(formula->asVIDAdjustEntries[
  3115. 0
  3116. ].usVoltageValue);
  3117. return 0;
  3118. }
  3119. }
  3120. break;
  3121. default:
  3122. DRM_ERROR("unknown voltage object table\n");
  3123. return -EINVAL;
  3124. }
  3125. }
  3126. return -EINVAL;
  3127. }
  3128. int radeon_atom_get_voltage_step(struct radeon_device *rdev,
  3129. u8 voltage_type, u16 *voltage_step)
  3130. {
  3131. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3132. u8 frev, crev;
  3133. u16 data_offset, size;
  3134. union voltage_object_info *voltage_info;
  3135. union voltage_object *voltage_object = NULL;
  3136. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3137. &frev, &crev, &data_offset)) {
  3138. voltage_info = (union voltage_object_info *)
  3139. (rdev->mode_info.atom_context->bios + data_offset);
  3140. switch (crev) {
  3141. case 1:
  3142. voltage_object = (union voltage_object *)
  3143. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3144. if (voltage_object) {
  3145. ATOM_VOLTAGE_FORMULA *formula =
  3146. &voltage_object->v1.asFormula;
  3147. if (formula->ucFlag & 1)
  3148. *voltage_step =
  3149. (le16_to_cpu(formula->usVoltageStep) + 1) / 2;
  3150. else
  3151. *voltage_step =
  3152. le16_to_cpu(formula->usVoltageStep);
  3153. return 0;
  3154. }
  3155. break;
  3156. case 2:
  3157. return -EINVAL;
  3158. default:
  3159. DRM_ERROR("unknown voltage object table\n");
  3160. return -EINVAL;
  3161. }
  3162. }
  3163. return -EINVAL;
  3164. }
  3165. int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
  3166. u8 voltage_type,
  3167. u16 nominal_voltage,
  3168. u16 *true_voltage)
  3169. {
  3170. u16 min_voltage, max_voltage, voltage_step;
  3171. if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage))
  3172. return -EINVAL;
  3173. if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage))
  3174. return -EINVAL;
  3175. if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step))
  3176. return -EINVAL;
  3177. if (nominal_voltage <= min_voltage)
  3178. *true_voltage = min_voltage;
  3179. else if (nominal_voltage >= max_voltage)
  3180. *true_voltage = max_voltage;
  3181. else
  3182. *true_voltage = min_voltage +
  3183. ((nominal_voltage - min_voltage) / voltage_step) *
  3184. voltage_step;
  3185. return 0;
  3186. }
  3187. int radeon_atom_get_voltage_table(struct radeon_device *rdev,
  3188. u8 voltage_type, u8 voltage_mode,
  3189. struct atom_voltage_table *voltage_table)
  3190. {
  3191. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3192. u8 frev, crev;
  3193. u16 data_offset, size;
  3194. int i, ret;
  3195. union voltage_object_info *voltage_info;
  3196. union voltage_object *voltage_object = NULL;
  3197. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3198. &frev, &crev, &data_offset)) {
  3199. voltage_info = (union voltage_object_info *)
  3200. (rdev->mode_info.atom_context->bios + data_offset);
  3201. switch (frev) {
  3202. case 1:
  3203. case 2:
  3204. switch (crev) {
  3205. case 1:
  3206. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3207. return -EINVAL;
  3208. case 2:
  3209. voltage_object = (union voltage_object *)
  3210. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3211. if (voltage_object) {
  3212. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3213. &voltage_object->v2.asFormula;
  3214. if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES)
  3215. return -EINVAL;
  3216. for (i = 0; i < formula->ucNumOfVoltageEntries; i++) {
  3217. voltage_table->entries[i].value =
  3218. le16_to_cpu(formula->asVIDAdjustEntries[i].usVoltageValue);
  3219. ret = radeon_atom_get_voltage_gpio_settings(rdev,
  3220. voltage_table->entries[i].value,
  3221. voltage_type,
  3222. &voltage_table->entries[i].smio_low,
  3223. &voltage_table->mask_low);
  3224. if (ret)
  3225. return ret;
  3226. }
  3227. voltage_table->count = formula->ucNumOfVoltageEntries;
  3228. return 0;
  3229. }
  3230. break;
  3231. default:
  3232. DRM_ERROR("unknown voltage object table\n");
  3233. return -EINVAL;
  3234. }
  3235. break;
  3236. case 3:
  3237. switch (crev) {
  3238. case 1:
  3239. voltage_object = (union voltage_object *)
  3240. atom_lookup_voltage_object_v3(&voltage_info->v3,
  3241. voltage_type, voltage_mode);
  3242. if (voltage_object) {
  3243. ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
  3244. &voltage_object->v3.asGpioVoltageObj;
  3245. if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
  3246. return -EINVAL;
  3247. for (i = 0; i < gpio->ucGpioEntryNum; i++) {
  3248. voltage_table->entries[i].value =
  3249. le16_to_cpu(gpio->asVolGpioLut[i].usVoltageValue);
  3250. voltage_table->entries[i].smio_low =
  3251. le32_to_cpu(gpio->asVolGpioLut[i].ulVoltageId);
  3252. }
  3253. voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
  3254. voltage_table->count = gpio->ucGpioEntryNum;
  3255. voltage_table->phase_delay = gpio->ucPhaseDelay;
  3256. return 0;
  3257. }
  3258. break;
  3259. default:
  3260. DRM_ERROR("unknown voltage object table\n");
  3261. return -EINVAL;
  3262. }
  3263. break;
  3264. default:
  3265. DRM_ERROR("unknown voltage object table\n");
  3266. return -EINVAL;
  3267. }
  3268. }
  3269. return -EINVAL;
  3270. }
  3271. union vram_info {
  3272. struct _ATOM_VRAM_INFO_V3 v1_3;
  3273. struct _ATOM_VRAM_INFO_V4 v1_4;
  3274. struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
  3275. };
  3276. int radeon_atom_get_memory_info(struct radeon_device *rdev,
  3277. u8 module_index, struct atom_memory_info *mem_info)
  3278. {
  3279. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3280. u8 frev, crev, i;
  3281. u16 data_offset, size;
  3282. union vram_info *vram_info;
  3283. memset(mem_info, 0, sizeof(struct atom_memory_info));
  3284. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3285. &frev, &crev, &data_offset)) {
  3286. vram_info = (union vram_info *)
  3287. (rdev->mode_info.atom_context->bios + data_offset);
  3288. switch (frev) {
  3289. case 1:
  3290. switch (crev) {
  3291. case 3:
  3292. /* r6xx */
  3293. if (module_index < vram_info->v1_3.ucNumOfVRAMModule) {
  3294. ATOM_VRAM_MODULE_V3 *vram_module =
  3295. (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo;
  3296. for (i = 0; i < module_index; i++) {
  3297. if (le16_to_cpu(vram_module->usSize) == 0)
  3298. return -EINVAL;
  3299. vram_module = (ATOM_VRAM_MODULE_V3 *)
  3300. ((u8 *)vram_module + le16_to_cpu(vram_module->usSize));
  3301. }
  3302. mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf;
  3303. mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0;
  3304. } else
  3305. return -EINVAL;
  3306. break;
  3307. case 4:
  3308. /* r7xx, evergreen */
  3309. if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
  3310. ATOM_VRAM_MODULE_V4 *vram_module =
  3311. (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
  3312. for (i = 0; i < module_index; i++) {
  3313. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3314. return -EINVAL;
  3315. vram_module = (ATOM_VRAM_MODULE_V4 *)
  3316. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3317. }
  3318. mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
  3319. mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
  3320. } else
  3321. return -EINVAL;
  3322. break;
  3323. default:
  3324. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3325. return -EINVAL;
  3326. }
  3327. break;
  3328. case 2:
  3329. switch (crev) {
  3330. case 1:
  3331. /* ni */
  3332. if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
  3333. ATOM_VRAM_MODULE_V7 *vram_module =
  3334. (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo;
  3335. for (i = 0; i < module_index; i++) {
  3336. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3337. return -EINVAL;
  3338. vram_module = (ATOM_VRAM_MODULE_V7 *)
  3339. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3340. }
  3341. mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
  3342. mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
  3343. } else
  3344. return -EINVAL;
  3345. break;
  3346. default:
  3347. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3348. return -EINVAL;
  3349. }
  3350. break;
  3351. default:
  3352. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3353. return -EINVAL;
  3354. }
  3355. return 0;
  3356. }
  3357. return -EINVAL;
  3358. }
  3359. int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
  3360. bool gddr5, u8 module_index,
  3361. struct atom_memory_clock_range_table *mclk_range_table)
  3362. {
  3363. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3364. u8 frev, crev, i;
  3365. u16 data_offset, size;
  3366. union vram_info *vram_info;
  3367. u32 mem_timing_size = gddr5 ?
  3368. sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT);
  3369. u8 *p;
  3370. memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table));
  3371. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3372. &frev, &crev, &data_offset)) {
  3373. vram_info = (union vram_info *)
  3374. (rdev->mode_info.atom_context->bios + data_offset);
  3375. switch (frev) {
  3376. case 1:
  3377. switch (crev) {
  3378. case 3:
  3379. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3380. return -EINVAL;
  3381. case 4:
  3382. /* r7xx, evergreen */
  3383. if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
  3384. ATOM_VRAM_MODULE_V4 *vram_module =
  3385. (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
  3386. for (i = 0; i < module_index; i++) {
  3387. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3388. return -EINVAL;
  3389. vram_module = (ATOM_VRAM_MODULE_V4 *)
  3390. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3391. }
  3392. mclk_range_table->num_entries = (u8)
  3393. ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) /
  3394. mem_timing_size);
  3395. p = (u8 *)&vram_module->asMemTiming[0];
  3396. for (i = 0; i < mclk_range_table->num_entries; i++) {
  3397. ATOM_MEMORY_TIMING_FORMAT *format = (ATOM_MEMORY_TIMING_FORMAT *)p;
  3398. mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange);
  3399. p += mem_timing_size;
  3400. }
  3401. } else
  3402. return -EINVAL;
  3403. break;
  3404. default:
  3405. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3406. return -EINVAL;
  3407. }
  3408. break;
  3409. case 2:
  3410. DRM_ERROR("new table version %d, %d\n", frev, crev);
  3411. return -EINVAL;
  3412. default:
  3413. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3414. return -EINVAL;
  3415. }
  3416. return 0;
  3417. }
  3418. return -EINVAL;
  3419. }
  3420. #define MEM_ID_MASK 0xff000000
  3421. #define MEM_ID_SHIFT 24
  3422. #define CLOCK_RANGE_MASK 0x00ffffff
  3423. #define CLOCK_RANGE_SHIFT 0
  3424. #define LOW_NIBBLE_MASK 0xf
  3425. #define DATA_EQU_PREV 0
  3426. #define DATA_FROM_TABLE 4
  3427. int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
  3428. u8 module_index,
  3429. struct atom_mc_reg_table *reg_table)
  3430. {
  3431. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3432. u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
  3433. u32 i = 0, j;
  3434. u16 data_offset, size;
  3435. union vram_info *vram_info;
  3436. memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
  3437. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3438. &frev, &crev, &data_offset)) {
  3439. vram_info = (union vram_info *)
  3440. (rdev->mode_info.atom_context->bios + data_offset);
  3441. switch (frev) {
  3442. case 1:
  3443. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3444. return -EINVAL;
  3445. case 2:
  3446. switch (crev) {
  3447. case 1:
  3448. if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
  3449. ATOM_INIT_REG_BLOCK *reg_block =
  3450. (ATOM_INIT_REG_BLOCK *)
  3451. ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
  3452. ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
  3453. (ATOM_MEMORY_SETTING_DATA_BLOCK *)
  3454. ((u8 *)reg_block + (2 * sizeof(u16)) +
  3455. le16_to_cpu(reg_block->usRegIndexTblSize));
  3456. ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
  3457. num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
  3458. sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
  3459. if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
  3460. return -EINVAL;
  3461. while (i < num_entries) {
  3462. if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
  3463. break;
  3464. reg_table->mc_reg_address[i].s1 =
  3465. (u16)(le16_to_cpu(format->usRegIndex));
  3466. reg_table->mc_reg_address[i].pre_reg_data =
  3467. (u8)(format->ucPreRegDataLength);
  3468. i++;
  3469. format = (ATOM_INIT_REG_INDEX_FORMAT *)
  3470. ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
  3471. }
  3472. reg_table->last = i;
  3473. while ((*(u32 *)reg_data != END_OF_REG_DATA_BLOCK) &&
  3474. (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
  3475. t_mem_id = (u8)((*(u32 *)reg_data & MEM_ID_MASK) >> MEM_ID_SHIFT);
  3476. if (module_index == t_mem_id) {
  3477. reg_table->mc_reg_table_entry[num_ranges].mclk_max =
  3478. (u32)((*(u32 *)reg_data & CLOCK_RANGE_MASK) >> CLOCK_RANGE_SHIFT);
  3479. for (i = 0, j = 1; i < reg_table->last; i++) {
  3480. if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
  3481. reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
  3482. (u32)*((u32 *)reg_data + j);
  3483. j++;
  3484. } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
  3485. reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
  3486. reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
  3487. }
  3488. }
  3489. num_ranges++;
  3490. }
  3491. reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
  3492. ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
  3493. }
  3494. if (*(u32 *)reg_data != END_OF_REG_DATA_BLOCK)
  3495. return -EINVAL;
  3496. reg_table->num_entries = num_ranges;
  3497. } else
  3498. return -EINVAL;
  3499. break;
  3500. default:
  3501. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3502. return -EINVAL;
  3503. }
  3504. break;
  3505. default:
  3506. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3507. return -EINVAL;
  3508. }
  3509. return 0;
  3510. }
  3511. return -EINVAL;
  3512. }
  3513. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  3514. {
  3515. struct radeon_device *rdev = dev->dev_private;
  3516. uint32_t bios_2_scratch, bios_6_scratch;
  3517. if (rdev->family >= CHIP_R600) {
  3518. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  3519. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3520. } else {
  3521. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  3522. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3523. }
  3524. /* let the bios control the backlight */
  3525. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  3526. /* tell the bios not to handle mode switching */
  3527. bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
  3528. if (rdev->family >= CHIP_R600) {
  3529. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  3530. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3531. } else {
  3532. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  3533. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3534. }
  3535. }
  3536. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  3537. {
  3538. uint32_t scratch_reg;
  3539. int i;
  3540. if (rdev->family >= CHIP_R600)
  3541. scratch_reg = R600_BIOS_0_SCRATCH;
  3542. else
  3543. scratch_reg = RADEON_BIOS_0_SCRATCH;
  3544. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  3545. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  3546. }
  3547. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  3548. {
  3549. uint32_t scratch_reg;
  3550. int i;
  3551. if (rdev->family >= CHIP_R600)
  3552. scratch_reg = R600_BIOS_0_SCRATCH;
  3553. else
  3554. scratch_reg = RADEON_BIOS_0_SCRATCH;
  3555. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  3556. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  3557. }
  3558. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  3559. {
  3560. struct drm_device *dev = encoder->dev;
  3561. struct radeon_device *rdev = dev->dev_private;
  3562. uint32_t bios_6_scratch;
  3563. if (rdev->family >= CHIP_R600)
  3564. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3565. else
  3566. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3567. if (lock) {
  3568. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  3569. bios_6_scratch &= ~ATOM_S6_ACC_MODE;
  3570. } else {
  3571. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  3572. bios_6_scratch |= ATOM_S6_ACC_MODE;
  3573. }
  3574. if (rdev->family >= CHIP_R600)
  3575. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3576. else
  3577. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3578. }
  3579. /* at some point we may want to break this out into individual functions */
  3580. void
  3581. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  3582. struct drm_encoder *encoder,
  3583. bool connected)
  3584. {
  3585. struct drm_device *dev = connector->dev;
  3586. struct radeon_device *rdev = dev->dev_private;
  3587. struct radeon_connector *radeon_connector =
  3588. to_radeon_connector(connector);
  3589. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3590. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  3591. if (rdev->family >= CHIP_R600) {
  3592. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  3593. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  3594. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3595. } else {
  3596. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3597. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  3598. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3599. }
  3600. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3601. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3602. if (connected) {
  3603. DRM_DEBUG_KMS("TV1 connected\n");
  3604. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  3605. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  3606. } else {
  3607. DRM_DEBUG_KMS("TV1 disconnected\n");
  3608. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  3609. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  3610. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  3611. }
  3612. }
  3613. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  3614. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  3615. if (connected) {
  3616. DRM_DEBUG_KMS("CV connected\n");
  3617. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  3618. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  3619. } else {
  3620. DRM_DEBUG_KMS("CV disconnected\n");
  3621. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  3622. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  3623. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  3624. }
  3625. }
  3626. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3627. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3628. if (connected) {
  3629. DRM_DEBUG_KMS("LCD1 connected\n");
  3630. bios_0_scratch |= ATOM_S0_LCD1;
  3631. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  3632. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  3633. } else {
  3634. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3635. bios_0_scratch &= ~ATOM_S0_LCD1;
  3636. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  3637. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  3638. }
  3639. }
  3640. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3641. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3642. if (connected) {
  3643. DRM_DEBUG_KMS("CRT1 connected\n");
  3644. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  3645. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  3646. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  3647. } else {
  3648. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3649. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  3650. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  3651. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  3652. }
  3653. }
  3654. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3655. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3656. if (connected) {
  3657. DRM_DEBUG_KMS("CRT2 connected\n");
  3658. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  3659. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  3660. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  3661. } else {
  3662. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3663. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  3664. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  3665. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  3666. }
  3667. }
  3668. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3669. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3670. if (connected) {
  3671. DRM_DEBUG_KMS("DFP1 connected\n");
  3672. bios_0_scratch |= ATOM_S0_DFP1;
  3673. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  3674. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  3675. } else {
  3676. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3677. bios_0_scratch &= ~ATOM_S0_DFP1;
  3678. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  3679. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  3680. }
  3681. }
  3682. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3683. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3684. if (connected) {
  3685. DRM_DEBUG_KMS("DFP2 connected\n");
  3686. bios_0_scratch |= ATOM_S0_DFP2;
  3687. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  3688. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  3689. } else {
  3690. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3691. bios_0_scratch &= ~ATOM_S0_DFP2;
  3692. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  3693. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  3694. }
  3695. }
  3696. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  3697. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  3698. if (connected) {
  3699. DRM_DEBUG_KMS("DFP3 connected\n");
  3700. bios_0_scratch |= ATOM_S0_DFP3;
  3701. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  3702. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  3703. } else {
  3704. DRM_DEBUG_KMS("DFP3 disconnected\n");
  3705. bios_0_scratch &= ~ATOM_S0_DFP3;
  3706. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  3707. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  3708. }
  3709. }
  3710. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  3711. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  3712. if (connected) {
  3713. DRM_DEBUG_KMS("DFP4 connected\n");
  3714. bios_0_scratch |= ATOM_S0_DFP4;
  3715. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  3716. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  3717. } else {
  3718. DRM_DEBUG_KMS("DFP4 disconnected\n");
  3719. bios_0_scratch &= ~ATOM_S0_DFP4;
  3720. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  3721. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  3722. }
  3723. }
  3724. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  3725. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  3726. if (connected) {
  3727. DRM_DEBUG_KMS("DFP5 connected\n");
  3728. bios_0_scratch |= ATOM_S0_DFP5;
  3729. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  3730. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  3731. } else {
  3732. DRM_DEBUG_KMS("DFP5 disconnected\n");
  3733. bios_0_scratch &= ~ATOM_S0_DFP5;
  3734. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  3735. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  3736. }
  3737. }
  3738. if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
  3739. (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
  3740. if (connected) {
  3741. DRM_DEBUG_KMS("DFP6 connected\n");
  3742. bios_0_scratch |= ATOM_S0_DFP6;
  3743. bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
  3744. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
  3745. } else {
  3746. DRM_DEBUG_KMS("DFP6 disconnected\n");
  3747. bios_0_scratch &= ~ATOM_S0_DFP6;
  3748. bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
  3749. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
  3750. }
  3751. }
  3752. if (rdev->family >= CHIP_R600) {
  3753. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  3754. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  3755. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3756. } else {
  3757. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3758. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  3759. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3760. }
  3761. }
  3762. void
  3763. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3764. {
  3765. struct drm_device *dev = encoder->dev;
  3766. struct radeon_device *rdev = dev->dev_private;
  3767. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3768. uint32_t bios_3_scratch;
  3769. if (ASIC_IS_DCE4(rdev))
  3770. return;
  3771. if (rdev->family >= CHIP_R600)
  3772. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  3773. else
  3774. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  3775. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3776. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  3777. bios_3_scratch |= (crtc << 18);
  3778. }
  3779. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  3780. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  3781. bios_3_scratch |= (crtc << 24);
  3782. }
  3783. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3784. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  3785. bios_3_scratch |= (crtc << 16);
  3786. }
  3787. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3788. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  3789. bios_3_scratch |= (crtc << 20);
  3790. }
  3791. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3792. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  3793. bios_3_scratch |= (crtc << 17);
  3794. }
  3795. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3796. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  3797. bios_3_scratch |= (crtc << 19);
  3798. }
  3799. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3800. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  3801. bios_3_scratch |= (crtc << 23);
  3802. }
  3803. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  3804. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  3805. bios_3_scratch |= (crtc << 25);
  3806. }
  3807. if (rdev->family >= CHIP_R600)
  3808. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  3809. else
  3810. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  3811. }
  3812. void
  3813. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3814. {
  3815. struct drm_device *dev = encoder->dev;
  3816. struct radeon_device *rdev = dev->dev_private;
  3817. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3818. uint32_t bios_2_scratch;
  3819. if (ASIC_IS_DCE4(rdev))
  3820. return;
  3821. if (rdev->family >= CHIP_R600)
  3822. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  3823. else
  3824. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  3825. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3826. if (on)
  3827. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  3828. else
  3829. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  3830. }
  3831. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  3832. if (on)
  3833. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  3834. else
  3835. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  3836. }
  3837. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3838. if (on)
  3839. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  3840. else
  3841. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  3842. }
  3843. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3844. if (on)
  3845. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  3846. else
  3847. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  3848. }
  3849. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3850. if (on)
  3851. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  3852. else
  3853. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  3854. }
  3855. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3856. if (on)
  3857. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  3858. else
  3859. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  3860. }
  3861. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3862. if (on)
  3863. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  3864. else
  3865. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  3866. }
  3867. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  3868. if (on)
  3869. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  3870. else
  3871. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  3872. }
  3873. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  3874. if (on)
  3875. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  3876. else
  3877. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  3878. }
  3879. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  3880. if (on)
  3881. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  3882. else
  3883. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  3884. }
  3885. if (rdev->family >= CHIP_R600)
  3886. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  3887. else
  3888. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  3889. }