radeon_atombios.c 142 KB

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