radeon_atombios.c 143 KB

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