radeon_atombios.c 142 KB

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