radeon_atombios.c 144 KB

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