radeon_atombios.c 138 KB

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