radeon_atombios.c 139 KB

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