radeon_atombios.c 131 KB

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