radeon_atombios.c 143 KB

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