radeon_atombios.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977
  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 "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. /* from radeon_encoder.c */
  32. extern uint32_t
  33. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
  34. uint8_t dac);
  35. extern void radeon_link_encoder_connector(struct drm_device *dev);
  36. extern void
  37. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
  38. uint32_t supported_device, u16 caps);
  39. /* from radeon_connector.c */
  40. extern void
  41. radeon_add_atom_connector(struct drm_device *dev,
  42. uint32_t connector_id,
  43. uint32_t supported_device,
  44. int connector_type,
  45. struct radeon_i2c_bus_rec *i2c_bus,
  46. uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd,
  49. struct radeon_router *router);
  50. /* from radeon_legacy_encoder.c */
  51. extern void
  52. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  53. uint32_t supported_device);
  54. union atom_supported_devices {
  55. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  56. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  57. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  58. };
  59. static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  60. uint8_t id)
  61. {
  62. struct atom_context *ctx = rdev->mode_info.atom_context;
  63. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  64. struct radeon_i2c_bus_rec i2c;
  65. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  66. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  67. uint16_t data_offset, size;
  68. int i, num_indices;
  69. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  70. i2c.valid = false;
  71. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  72. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  73. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  74. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  75. for (i = 0; i < num_indices; i++) {
  76. gpio = &i2c_info->asGPIO_Info[i];
  77. /* some evergreen boards have bad data for this entry */
  78. if (ASIC_IS_DCE4(rdev)) {
  79. if ((i == 7) &&
  80. (gpio->usClkMaskRegisterIndex == 0x1936) &&
  81. (gpio->sucI2cId.ucAccess == 0)) {
  82. gpio->sucI2cId.ucAccess = 0x97;
  83. gpio->ucDataMaskShift = 8;
  84. gpio->ucDataEnShift = 8;
  85. gpio->ucDataY_Shift = 8;
  86. gpio->ucDataA_Shift = 8;
  87. }
  88. }
  89. /* some DCE3 boards have bad data for this entry */
  90. if (ASIC_IS_DCE3(rdev)) {
  91. if ((i == 4) &&
  92. (gpio->usClkMaskRegisterIndex == 0x1fda) &&
  93. (gpio->sucI2cId.ucAccess == 0x94))
  94. gpio->sucI2cId.ucAccess = 0x14;
  95. }
  96. if (gpio->sucI2cId.ucAccess == id) {
  97. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  98. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  99. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  100. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  101. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  102. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  103. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  104. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  105. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  106. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  107. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  108. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  109. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  110. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  111. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  112. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  113. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  114. i2c.hw_capable = true;
  115. else
  116. i2c.hw_capable = false;
  117. if (gpio->sucI2cId.ucAccess == 0xa0)
  118. i2c.mm_i2c = true;
  119. else
  120. i2c.mm_i2c = false;
  121. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  122. if (i2c.mask_clk_reg)
  123. i2c.valid = true;
  124. break;
  125. }
  126. }
  127. }
  128. return i2c;
  129. }
  130. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  131. {
  132. struct atom_context *ctx = rdev->mode_info.atom_context;
  133. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  134. struct radeon_i2c_bus_rec i2c;
  135. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  136. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  137. uint16_t data_offset, size;
  138. int i, num_indices;
  139. char stmp[32];
  140. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  141. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  142. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  143. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  144. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  145. for (i = 0; i < num_indices; i++) {
  146. gpio = &i2c_info->asGPIO_Info[i];
  147. i2c.valid = false;
  148. /* some evergreen boards have bad data for this entry */
  149. if (ASIC_IS_DCE4(rdev)) {
  150. if ((i == 7) &&
  151. (gpio->usClkMaskRegisterIndex == 0x1936) &&
  152. (gpio->sucI2cId.ucAccess == 0)) {
  153. gpio->sucI2cId.ucAccess = 0x97;
  154. gpio->ucDataMaskShift = 8;
  155. gpio->ucDataEnShift = 8;
  156. gpio->ucDataY_Shift = 8;
  157. gpio->ucDataA_Shift = 8;
  158. }
  159. }
  160. /* some DCE3 boards have bad data for this entry */
  161. if (ASIC_IS_DCE3(rdev)) {
  162. if ((i == 4) &&
  163. (gpio->usClkMaskRegisterIndex == 0x1fda) &&
  164. (gpio->sucI2cId.ucAccess == 0x94))
  165. gpio->sucI2cId.ucAccess = 0x14;
  166. }
  167. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  168. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  169. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  170. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  171. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  172. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  173. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  174. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  175. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  176. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  177. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  178. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  179. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  180. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  181. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  182. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  183. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  184. i2c.hw_capable = true;
  185. else
  186. i2c.hw_capable = false;
  187. if (gpio->sucI2cId.ucAccess == 0xa0)
  188. i2c.mm_i2c = true;
  189. else
  190. i2c.mm_i2c = false;
  191. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  192. if (i2c.mask_clk_reg) {
  193. i2c.valid = true;
  194. sprintf(stmp, "0x%x", i2c.i2c_id);
  195. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  196. }
  197. }
  198. }
  199. }
  200. static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  201. u8 id)
  202. {
  203. struct atom_context *ctx = rdev->mode_info.atom_context;
  204. struct radeon_gpio_rec gpio;
  205. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  206. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  207. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  208. u16 data_offset, size;
  209. int i, num_indices;
  210. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  211. gpio.valid = false;
  212. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  213. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  214. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  215. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  216. for (i = 0; i < num_indices; i++) {
  217. pin = &gpio_info->asGPIO_Pin[i];
  218. if (id == pin->ucGPIO_ID) {
  219. gpio.id = pin->ucGPIO_ID;
  220. gpio.reg = pin->usGpioPin_AIndex * 4;
  221. gpio.mask = (1 << pin->ucGpioPinBitShift);
  222. gpio.valid = true;
  223. break;
  224. }
  225. }
  226. }
  227. return gpio;
  228. }
  229. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  230. struct radeon_gpio_rec *gpio)
  231. {
  232. struct radeon_hpd hpd;
  233. u32 reg;
  234. memset(&hpd, 0, sizeof(struct radeon_hpd));
  235. if (ASIC_IS_DCE4(rdev))
  236. reg = EVERGREEN_DC_GPIO_HPD_A;
  237. else
  238. reg = AVIVO_DC_GPIO_HPD_A;
  239. hpd.gpio = *gpio;
  240. if (gpio->reg == reg) {
  241. switch(gpio->mask) {
  242. case (1 << 0):
  243. hpd.hpd = RADEON_HPD_1;
  244. break;
  245. case (1 << 8):
  246. hpd.hpd = RADEON_HPD_2;
  247. break;
  248. case (1 << 16):
  249. hpd.hpd = RADEON_HPD_3;
  250. break;
  251. case (1 << 24):
  252. hpd.hpd = RADEON_HPD_4;
  253. break;
  254. case (1 << 26):
  255. hpd.hpd = RADEON_HPD_5;
  256. break;
  257. case (1 << 28):
  258. hpd.hpd = RADEON_HPD_6;
  259. break;
  260. default:
  261. hpd.hpd = RADEON_HPD_NONE;
  262. break;
  263. }
  264. } else
  265. hpd.hpd = RADEON_HPD_NONE;
  266. return hpd;
  267. }
  268. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  269. uint32_t supported_device,
  270. int *connector_type,
  271. struct radeon_i2c_bus_rec *i2c_bus,
  272. uint16_t *line_mux,
  273. struct radeon_hpd *hpd)
  274. {
  275. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  276. if ((dev->pdev->device == 0x791e) &&
  277. (dev->pdev->subsystem_vendor == 0x1043) &&
  278. (dev->pdev->subsystem_device == 0x826d)) {
  279. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  280. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  281. *connector_type = DRM_MODE_CONNECTOR_DVID;
  282. }
  283. /* Asrock RS600 board lists the DVI port as HDMI */
  284. if ((dev->pdev->device == 0x7941) &&
  285. (dev->pdev->subsystem_vendor == 0x1849) &&
  286. (dev->pdev->subsystem_device == 0x7941)) {
  287. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  288. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  289. *connector_type = DRM_MODE_CONNECTOR_DVID;
  290. }
  291. /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
  292. if ((dev->pdev->device == 0x796e) &&
  293. (dev->pdev->subsystem_vendor == 0x1462) &&
  294. (dev->pdev->subsystem_device == 0x7302)) {
  295. if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
  296. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  297. return false;
  298. }
  299. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  300. if ((dev->pdev->device == 0x7941) &&
  301. (dev->pdev->subsystem_vendor == 0x147b) &&
  302. (dev->pdev->subsystem_device == 0x2412)) {
  303. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  304. return false;
  305. }
  306. /* Falcon NW laptop lists vga ddc line for LVDS */
  307. if ((dev->pdev->device == 0x5653) &&
  308. (dev->pdev->subsystem_vendor == 0x1462) &&
  309. (dev->pdev->subsystem_device == 0x0291)) {
  310. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  311. i2c_bus->valid = false;
  312. *line_mux = 53;
  313. }
  314. }
  315. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  316. if ((dev->pdev->device == 0x7146) &&
  317. (dev->pdev->subsystem_vendor == 0x17af) &&
  318. (dev->pdev->subsystem_device == 0x2058)) {
  319. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  320. return false;
  321. }
  322. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  323. if ((dev->pdev->device == 0x7142) &&
  324. (dev->pdev->subsystem_vendor == 0x1458) &&
  325. (dev->pdev->subsystem_device == 0x2134)) {
  326. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  327. return false;
  328. }
  329. /* Funky macbooks */
  330. if ((dev->pdev->device == 0x71C5) &&
  331. (dev->pdev->subsystem_vendor == 0x106b) &&
  332. (dev->pdev->subsystem_device == 0x0080)) {
  333. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  334. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  335. return false;
  336. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  337. *line_mux = 0x90;
  338. }
  339. /* mac rv630, rv730, others */
  340. if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
  341. (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
  342. *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
  343. *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
  344. }
  345. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  346. if ((dev->pdev->device == 0x9598) &&
  347. (dev->pdev->subsystem_vendor == 0x1043) &&
  348. (dev->pdev->subsystem_device == 0x01da)) {
  349. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  350. *connector_type = DRM_MODE_CONNECTOR_DVII;
  351. }
  352. }
  353. /* ASUS HD 3600 board lists the DVI port as HDMI */
  354. if ((dev->pdev->device == 0x9598) &&
  355. (dev->pdev->subsystem_vendor == 0x1043) &&
  356. (dev->pdev->subsystem_device == 0x01e4)) {
  357. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  358. *connector_type = DRM_MODE_CONNECTOR_DVII;
  359. }
  360. }
  361. /* ASUS HD 3450 board lists the DVI port as HDMI */
  362. if ((dev->pdev->device == 0x95C5) &&
  363. (dev->pdev->subsystem_vendor == 0x1043) &&
  364. (dev->pdev->subsystem_device == 0x01e2)) {
  365. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  366. *connector_type = DRM_MODE_CONNECTOR_DVII;
  367. }
  368. }
  369. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  370. * HDMI + VGA reporting as HDMI
  371. */
  372. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  373. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  374. *connector_type = DRM_MODE_CONNECTOR_VGA;
  375. *line_mux = 0;
  376. }
  377. }
  378. /* Acer laptop (Acer TravelMate 5730G) has an HDMI port
  379. * on the laptop and a DVI port on the docking station and
  380. * both share the same encoder, hpd pin, and ddc line.
  381. * So while the bios table is technically correct,
  382. * we drop the DVI port here since xrandr has no concept of
  383. * encoders and will try and drive both connectors
  384. * with different crtcs which isn't possible on the hardware
  385. * side and leaves no crtcs for LVDS or VGA.
  386. */
  387. if ((dev->pdev->device == 0x95c4) &&
  388. (dev->pdev->subsystem_vendor == 0x1025) &&
  389. (dev->pdev->subsystem_device == 0x013c)) {
  390. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  391. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  392. /* actually it's a DVI-D port not DVI-I */
  393. *connector_type = DRM_MODE_CONNECTOR_DVID;
  394. return false;
  395. }
  396. }
  397. /* XFX Pine Group device rv730 reports no VGA DDC lines
  398. * even though they are wired up to record 0x93
  399. */
  400. if ((dev->pdev->device == 0x9498) &&
  401. (dev->pdev->subsystem_vendor == 0x1682) &&
  402. (dev->pdev->subsystem_device == 0x2452)) {
  403. struct radeon_device *rdev = dev->dev_private;
  404. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  405. }
  406. return true;
  407. }
  408. const int supported_devices_connector_convert[] = {
  409. DRM_MODE_CONNECTOR_Unknown,
  410. DRM_MODE_CONNECTOR_VGA,
  411. DRM_MODE_CONNECTOR_DVII,
  412. DRM_MODE_CONNECTOR_DVID,
  413. DRM_MODE_CONNECTOR_DVIA,
  414. DRM_MODE_CONNECTOR_SVIDEO,
  415. DRM_MODE_CONNECTOR_Composite,
  416. DRM_MODE_CONNECTOR_LVDS,
  417. DRM_MODE_CONNECTOR_Unknown,
  418. DRM_MODE_CONNECTOR_Unknown,
  419. DRM_MODE_CONNECTOR_HDMIA,
  420. DRM_MODE_CONNECTOR_HDMIB,
  421. DRM_MODE_CONNECTOR_Unknown,
  422. DRM_MODE_CONNECTOR_Unknown,
  423. DRM_MODE_CONNECTOR_9PinDIN,
  424. DRM_MODE_CONNECTOR_DisplayPort
  425. };
  426. const uint16_t supported_devices_connector_object_id_convert[] = {
  427. CONNECTOR_OBJECT_ID_NONE,
  428. CONNECTOR_OBJECT_ID_VGA,
  429. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  430. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  431. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  432. CONNECTOR_OBJECT_ID_COMPOSITE,
  433. CONNECTOR_OBJECT_ID_SVIDEO,
  434. CONNECTOR_OBJECT_ID_LVDS,
  435. CONNECTOR_OBJECT_ID_9PIN_DIN,
  436. CONNECTOR_OBJECT_ID_9PIN_DIN,
  437. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  438. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  439. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  440. CONNECTOR_OBJECT_ID_SVIDEO
  441. };
  442. const int object_connector_convert[] = {
  443. DRM_MODE_CONNECTOR_Unknown,
  444. DRM_MODE_CONNECTOR_DVII,
  445. DRM_MODE_CONNECTOR_DVII,
  446. DRM_MODE_CONNECTOR_DVID,
  447. DRM_MODE_CONNECTOR_DVID,
  448. DRM_MODE_CONNECTOR_VGA,
  449. DRM_MODE_CONNECTOR_Composite,
  450. DRM_MODE_CONNECTOR_SVIDEO,
  451. DRM_MODE_CONNECTOR_Unknown,
  452. DRM_MODE_CONNECTOR_Unknown,
  453. DRM_MODE_CONNECTOR_9PinDIN,
  454. DRM_MODE_CONNECTOR_Unknown,
  455. DRM_MODE_CONNECTOR_HDMIA,
  456. DRM_MODE_CONNECTOR_HDMIB,
  457. DRM_MODE_CONNECTOR_LVDS,
  458. DRM_MODE_CONNECTOR_9PinDIN,
  459. DRM_MODE_CONNECTOR_Unknown,
  460. DRM_MODE_CONNECTOR_Unknown,
  461. DRM_MODE_CONNECTOR_Unknown,
  462. DRM_MODE_CONNECTOR_DisplayPort,
  463. DRM_MODE_CONNECTOR_eDP,
  464. DRM_MODE_CONNECTOR_Unknown
  465. };
  466. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  467. {
  468. struct radeon_device *rdev = dev->dev_private;
  469. struct radeon_mode_info *mode_info = &rdev->mode_info;
  470. struct atom_context *ctx = mode_info->atom_context;
  471. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  472. u16 size, data_offset;
  473. u8 frev, crev;
  474. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  475. ATOM_ENCODER_OBJECT_TABLE *enc_obj;
  476. ATOM_OBJECT_TABLE *router_obj;
  477. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  478. ATOM_OBJECT_HEADER *obj_header;
  479. int i, j, k, path_size, device_support;
  480. int connector_type;
  481. u16 igp_lane_info, conn_id, connector_object_id;
  482. struct radeon_i2c_bus_rec ddc_bus;
  483. struct radeon_router router;
  484. struct radeon_gpio_rec gpio;
  485. struct radeon_hpd hpd;
  486. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  487. return false;
  488. if (crev < 2)
  489. return false;
  490. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  491. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  492. (ctx->bios + data_offset +
  493. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  494. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  495. (ctx->bios + data_offset +
  496. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  497. enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
  498. (ctx->bios + data_offset +
  499. le16_to_cpu(obj_header->usEncoderObjectTableOffset));
  500. router_obj = (ATOM_OBJECT_TABLE *)
  501. (ctx->bios + data_offset +
  502. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  503. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  504. path_size = 0;
  505. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  506. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  507. ATOM_DISPLAY_OBJECT_PATH *path;
  508. addr += path_size;
  509. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  510. path_size += le16_to_cpu(path->usSize);
  511. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  512. uint8_t con_obj_id, con_obj_num, con_obj_type;
  513. con_obj_id =
  514. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  515. >> OBJECT_ID_SHIFT;
  516. con_obj_num =
  517. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  518. >> ENUM_ID_SHIFT;
  519. con_obj_type =
  520. (le16_to_cpu(path->usConnObjectId) &
  521. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  522. /* TODO CV support */
  523. if (le16_to_cpu(path->usDeviceTag) ==
  524. ATOM_DEVICE_CV_SUPPORT)
  525. continue;
  526. /* IGP chips */
  527. if ((rdev->flags & RADEON_IS_IGP) &&
  528. (con_obj_id ==
  529. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  530. uint16_t igp_offset = 0;
  531. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  532. index =
  533. GetIndexIntoMasterTable(DATA,
  534. IntegratedSystemInfo);
  535. if (atom_parse_data_header(ctx, index, &size, &frev,
  536. &crev, &igp_offset)) {
  537. if (crev >= 2) {
  538. igp_obj =
  539. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  540. *) (ctx->bios + igp_offset);
  541. if (igp_obj) {
  542. uint32_t slot_config, ct;
  543. if (con_obj_num == 1)
  544. slot_config =
  545. igp_obj->
  546. ulDDISlot1Config;
  547. else
  548. slot_config =
  549. igp_obj->
  550. ulDDISlot2Config;
  551. ct = (slot_config >> 16) & 0xff;
  552. connector_type =
  553. object_connector_convert
  554. [ct];
  555. connector_object_id = ct;
  556. igp_lane_info =
  557. slot_config & 0xffff;
  558. } else
  559. continue;
  560. } else
  561. continue;
  562. } else {
  563. igp_lane_info = 0;
  564. connector_type =
  565. object_connector_convert[con_obj_id];
  566. connector_object_id = con_obj_id;
  567. }
  568. } else {
  569. igp_lane_info = 0;
  570. connector_type =
  571. object_connector_convert[con_obj_id];
  572. connector_object_id = con_obj_id;
  573. }
  574. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  575. continue;
  576. router.ddc_valid = false;
  577. router.cd_valid = false;
  578. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  579. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  580. grph_obj_id =
  581. (le16_to_cpu(path->usGraphicObjIds[j]) &
  582. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  583. grph_obj_num =
  584. (le16_to_cpu(path->usGraphicObjIds[j]) &
  585. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  586. grph_obj_type =
  587. (le16_to_cpu(path->usGraphicObjIds[j]) &
  588. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  589. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  590. for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
  591. u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
  592. if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
  593. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  594. (ctx->bios + data_offset +
  595. le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
  596. ATOM_ENCODER_CAP_RECORD *cap_record;
  597. u16 caps = 0;
  598. while (record->ucRecordType > 0 &&
  599. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  600. switch (record->ucRecordType) {
  601. case ATOM_ENCODER_CAP_RECORD_TYPE:
  602. cap_record =(ATOM_ENCODER_CAP_RECORD *)
  603. record;
  604. caps = le16_to_cpu(cap_record->usEncoderCap);
  605. break;
  606. }
  607. record = (ATOM_COMMON_RECORD_HEADER *)
  608. ((char *)record + record->ucRecordSize);
  609. }
  610. radeon_add_atom_encoder(dev,
  611. encoder_obj,
  612. le16_to_cpu
  613. (path->
  614. usDeviceTag),
  615. caps);
  616. }
  617. }
  618. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  619. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  620. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
  621. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  622. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  623. (ctx->bios + data_offset +
  624. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  625. ATOM_I2C_RECORD *i2c_record;
  626. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  627. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  628. ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
  629. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  630. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  631. (ctx->bios + data_offset +
  632. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  633. int enum_id;
  634. router.router_id = router_obj_id;
  635. for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
  636. enum_id++) {
  637. if (le16_to_cpu(path->usConnObjectId) ==
  638. le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
  639. break;
  640. }
  641. while (record->ucRecordType > 0 &&
  642. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  643. switch (record->ucRecordType) {
  644. case ATOM_I2C_RECORD_TYPE:
  645. i2c_record =
  646. (ATOM_I2C_RECORD *)
  647. record;
  648. i2c_config =
  649. (ATOM_I2C_ID_CONFIG_ACCESS *)
  650. &i2c_record->sucI2cId;
  651. router.i2c_info =
  652. radeon_lookup_i2c_gpio(rdev,
  653. i2c_config->
  654. ucAccess);
  655. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  656. break;
  657. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  658. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  659. record;
  660. router.ddc_valid = true;
  661. router.ddc_mux_type = ddc_path->ucMuxType;
  662. router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
  663. router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
  664. break;
  665. case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
  666. cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
  667. record;
  668. router.cd_valid = true;
  669. router.cd_mux_type = cd_path->ucMuxType;
  670. router.cd_mux_control_pin = cd_path->ucMuxControlPin;
  671. router.cd_mux_state = cd_path->ucMuxState[enum_id];
  672. break;
  673. }
  674. record = (ATOM_COMMON_RECORD_HEADER *)
  675. ((char *)record + record->ucRecordSize);
  676. }
  677. }
  678. }
  679. }
  680. }
  681. /* look up gpio for ddc, hpd */
  682. ddc_bus.valid = false;
  683. hpd.hpd = RADEON_HPD_NONE;
  684. if ((le16_to_cpu(path->usDeviceTag) &
  685. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  686. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  687. if (le16_to_cpu(path->usConnObjectId) ==
  688. le16_to_cpu(con_obj->asObjects[j].
  689. usObjectID)) {
  690. ATOM_COMMON_RECORD_HEADER
  691. *record =
  692. (ATOM_COMMON_RECORD_HEADER
  693. *)
  694. (ctx->bios + data_offset +
  695. le16_to_cpu(con_obj->
  696. asObjects[j].
  697. usRecordOffset));
  698. ATOM_I2C_RECORD *i2c_record;
  699. ATOM_HPD_INT_RECORD *hpd_record;
  700. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  701. while (record->ucRecordType > 0
  702. && record->
  703. ucRecordType <=
  704. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  705. switch (record->ucRecordType) {
  706. case ATOM_I2C_RECORD_TYPE:
  707. i2c_record =
  708. (ATOM_I2C_RECORD *)
  709. record;
  710. i2c_config =
  711. (ATOM_I2C_ID_CONFIG_ACCESS *)
  712. &i2c_record->sucI2cId;
  713. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  714. i2c_config->
  715. ucAccess);
  716. break;
  717. case ATOM_HPD_INT_RECORD_TYPE:
  718. hpd_record =
  719. (ATOM_HPD_INT_RECORD *)
  720. record;
  721. gpio = radeon_lookup_gpio(rdev,
  722. hpd_record->ucHPDIntGPIOID);
  723. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  724. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  725. break;
  726. }
  727. record =
  728. (ATOM_COMMON_RECORD_HEADER
  729. *) ((char *)record
  730. +
  731. record->
  732. ucRecordSize);
  733. }
  734. break;
  735. }
  736. }
  737. }
  738. /* needed for aux chan transactions */
  739. ddc_bus.hpd = hpd.hpd;
  740. conn_id = le16_to_cpu(path->usConnObjectId);
  741. if (!radeon_atom_apply_quirks
  742. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  743. &ddc_bus, &conn_id, &hpd))
  744. continue;
  745. radeon_add_atom_connector(dev,
  746. conn_id,
  747. le16_to_cpu(path->
  748. usDeviceTag),
  749. connector_type, &ddc_bus,
  750. igp_lane_info,
  751. connector_object_id,
  752. &hpd,
  753. &router);
  754. }
  755. }
  756. radeon_link_encoder_connector(dev);
  757. return true;
  758. }
  759. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  760. int connector_type,
  761. uint16_t devices)
  762. {
  763. struct radeon_device *rdev = dev->dev_private;
  764. if (rdev->flags & RADEON_IS_IGP) {
  765. return supported_devices_connector_object_id_convert
  766. [connector_type];
  767. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  768. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  769. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  770. struct radeon_mode_info *mode_info = &rdev->mode_info;
  771. struct atom_context *ctx = mode_info->atom_context;
  772. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  773. uint16_t size, data_offset;
  774. uint8_t frev, crev;
  775. ATOM_XTMDS_INFO *xtmds;
  776. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  777. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  778. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  779. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  780. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  781. else
  782. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  783. } else {
  784. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  785. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  786. else
  787. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  788. }
  789. } else
  790. return supported_devices_connector_object_id_convert
  791. [connector_type];
  792. } else {
  793. return supported_devices_connector_object_id_convert
  794. [connector_type];
  795. }
  796. }
  797. struct bios_connector {
  798. bool valid;
  799. uint16_t line_mux;
  800. uint16_t devices;
  801. int connector_type;
  802. struct radeon_i2c_bus_rec ddc_bus;
  803. struct radeon_hpd hpd;
  804. };
  805. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  806. drm_device
  807. *dev)
  808. {
  809. struct radeon_device *rdev = dev->dev_private;
  810. struct radeon_mode_info *mode_info = &rdev->mode_info;
  811. struct atom_context *ctx = mode_info->atom_context;
  812. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  813. uint16_t size, data_offset;
  814. uint8_t frev, crev;
  815. uint16_t device_support;
  816. uint8_t dac;
  817. union atom_supported_devices *supported_devices;
  818. int i, j, max_device;
  819. struct bios_connector *bios_connectors;
  820. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  821. struct radeon_router router;
  822. router.ddc_valid = false;
  823. router.cd_valid = false;
  824. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  825. if (!bios_connectors)
  826. return false;
  827. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  828. &data_offset)) {
  829. kfree(bios_connectors);
  830. return false;
  831. }
  832. supported_devices =
  833. (union atom_supported_devices *)(ctx->bios + data_offset);
  834. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  835. if (frev > 1)
  836. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  837. else
  838. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  839. for (i = 0; i < max_device; i++) {
  840. ATOM_CONNECTOR_INFO_I2C ci =
  841. supported_devices->info.asConnInfo[i];
  842. bios_connectors[i].valid = false;
  843. if (!(device_support & (1 << i))) {
  844. continue;
  845. }
  846. if (i == ATOM_DEVICE_CV_INDEX) {
  847. DRM_DEBUG_KMS("Skipping Component Video\n");
  848. continue;
  849. }
  850. bios_connectors[i].connector_type =
  851. supported_devices_connector_convert[ci.sucConnectorInfo.
  852. sbfAccess.
  853. bfConnectorType];
  854. if (bios_connectors[i].connector_type ==
  855. DRM_MODE_CONNECTOR_Unknown)
  856. continue;
  857. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  858. bios_connectors[i].line_mux =
  859. ci.sucI2cId.ucAccess;
  860. /* give tv unique connector ids */
  861. if (i == ATOM_DEVICE_TV1_INDEX) {
  862. bios_connectors[i].ddc_bus.valid = false;
  863. bios_connectors[i].line_mux = 50;
  864. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  865. bios_connectors[i].ddc_bus.valid = false;
  866. bios_connectors[i].line_mux = 51;
  867. } else if (i == ATOM_DEVICE_CV_INDEX) {
  868. bios_connectors[i].ddc_bus.valid = false;
  869. bios_connectors[i].line_mux = 52;
  870. } else
  871. bios_connectors[i].ddc_bus =
  872. radeon_lookup_i2c_gpio(rdev,
  873. bios_connectors[i].line_mux);
  874. if ((crev > 1) && (frev > 1)) {
  875. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  876. switch (isb) {
  877. case 0x4:
  878. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  879. break;
  880. case 0xa:
  881. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  882. break;
  883. default:
  884. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  885. break;
  886. }
  887. } else {
  888. if (i == ATOM_DEVICE_DFP1_INDEX)
  889. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  890. else if (i == ATOM_DEVICE_DFP2_INDEX)
  891. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  892. else
  893. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  894. }
  895. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  896. * shared with a DVI port, we'll pick up the DVI connector when we
  897. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  898. */
  899. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  900. bios_connectors[i].connector_type =
  901. DRM_MODE_CONNECTOR_VGA;
  902. if (!radeon_atom_apply_quirks
  903. (dev, (1 << i), &bios_connectors[i].connector_type,
  904. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  905. &bios_connectors[i].hpd))
  906. continue;
  907. bios_connectors[i].valid = true;
  908. bios_connectors[i].devices = (1 << i);
  909. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  910. radeon_add_atom_encoder(dev,
  911. radeon_get_encoder_enum(dev,
  912. (1 << i),
  913. dac),
  914. (1 << i),
  915. 0);
  916. else
  917. radeon_add_legacy_encoder(dev,
  918. radeon_get_encoder_enum(dev,
  919. (1 << i),
  920. dac),
  921. (1 << i));
  922. }
  923. /* combine shared connectors */
  924. for (i = 0; i < max_device; i++) {
  925. if (bios_connectors[i].valid) {
  926. for (j = 0; j < max_device; j++) {
  927. if (bios_connectors[j].valid && (i != j)) {
  928. if (bios_connectors[i].line_mux ==
  929. bios_connectors[j].line_mux) {
  930. /* make sure not to combine LVDS */
  931. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  932. bios_connectors[i].line_mux = 53;
  933. bios_connectors[i].ddc_bus.valid = false;
  934. continue;
  935. }
  936. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  937. bios_connectors[j].line_mux = 53;
  938. bios_connectors[j].ddc_bus.valid = false;
  939. continue;
  940. }
  941. /* combine analog and digital for DVI-I */
  942. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  943. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  944. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  945. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  946. bios_connectors[i].devices |=
  947. bios_connectors[j].devices;
  948. bios_connectors[i].connector_type =
  949. DRM_MODE_CONNECTOR_DVII;
  950. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  951. bios_connectors[i].hpd =
  952. bios_connectors[j].hpd;
  953. bios_connectors[j].valid = false;
  954. }
  955. }
  956. }
  957. }
  958. }
  959. }
  960. /* add the connectors */
  961. for (i = 0; i < max_device; i++) {
  962. if (bios_connectors[i].valid) {
  963. uint16_t connector_object_id =
  964. atombios_get_connector_object_id(dev,
  965. bios_connectors[i].connector_type,
  966. bios_connectors[i].devices);
  967. radeon_add_atom_connector(dev,
  968. bios_connectors[i].line_mux,
  969. bios_connectors[i].devices,
  970. bios_connectors[i].
  971. connector_type,
  972. &bios_connectors[i].ddc_bus,
  973. 0,
  974. connector_object_id,
  975. &bios_connectors[i].hpd,
  976. &router);
  977. }
  978. }
  979. radeon_link_encoder_connector(dev);
  980. kfree(bios_connectors);
  981. return true;
  982. }
  983. union firmware_info {
  984. ATOM_FIRMWARE_INFO info;
  985. ATOM_FIRMWARE_INFO_V1_2 info_12;
  986. ATOM_FIRMWARE_INFO_V1_3 info_13;
  987. ATOM_FIRMWARE_INFO_V1_4 info_14;
  988. ATOM_FIRMWARE_INFO_V2_1 info_21;
  989. ATOM_FIRMWARE_INFO_V2_2 info_22;
  990. };
  991. bool radeon_atom_get_clock_info(struct drm_device *dev)
  992. {
  993. struct radeon_device *rdev = dev->dev_private;
  994. struct radeon_mode_info *mode_info = &rdev->mode_info;
  995. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  996. union firmware_info *firmware_info;
  997. uint8_t frev, crev;
  998. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  999. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  1000. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  1001. struct radeon_pll *spll = &rdev->clock.spll;
  1002. struct radeon_pll *mpll = &rdev->clock.mpll;
  1003. uint16_t data_offset;
  1004. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1005. &frev, &crev, &data_offset)) {
  1006. firmware_info =
  1007. (union firmware_info *)(mode_info->atom_context->bios +
  1008. data_offset);
  1009. /* pixel clocks */
  1010. p1pll->reference_freq =
  1011. le16_to_cpu(firmware_info->info.usReferenceClock);
  1012. p1pll->reference_div = 0;
  1013. if (crev < 2)
  1014. p1pll->pll_out_min =
  1015. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  1016. else
  1017. p1pll->pll_out_min =
  1018. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  1019. p1pll->pll_out_max =
  1020. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  1021. if (crev >= 4) {
  1022. p1pll->lcd_pll_out_min =
  1023. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  1024. if (p1pll->lcd_pll_out_min == 0)
  1025. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1026. p1pll->lcd_pll_out_max =
  1027. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  1028. if (p1pll->lcd_pll_out_max == 0)
  1029. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1030. } else {
  1031. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1032. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1033. }
  1034. if (p1pll->pll_out_min == 0) {
  1035. if (ASIC_IS_AVIVO(rdev))
  1036. p1pll->pll_out_min = 64800;
  1037. else
  1038. p1pll->pll_out_min = 20000;
  1039. }
  1040. p1pll->pll_in_min =
  1041. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  1042. p1pll->pll_in_max =
  1043. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  1044. *p2pll = *p1pll;
  1045. /* system clock */
  1046. if (ASIC_IS_DCE4(rdev))
  1047. spll->reference_freq =
  1048. le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
  1049. else
  1050. spll->reference_freq =
  1051. le16_to_cpu(firmware_info->info.usReferenceClock);
  1052. spll->reference_div = 0;
  1053. spll->pll_out_min =
  1054. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1055. spll->pll_out_max =
  1056. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1057. /* ??? */
  1058. if (spll->pll_out_min == 0) {
  1059. if (ASIC_IS_AVIVO(rdev))
  1060. spll->pll_out_min = 64800;
  1061. else
  1062. spll->pll_out_min = 20000;
  1063. }
  1064. spll->pll_in_min =
  1065. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1066. spll->pll_in_max =
  1067. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1068. /* memory clock */
  1069. if (ASIC_IS_DCE4(rdev))
  1070. mpll->reference_freq =
  1071. le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
  1072. else
  1073. mpll->reference_freq =
  1074. le16_to_cpu(firmware_info->info.usReferenceClock);
  1075. mpll->reference_div = 0;
  1076. mpll->pll_out_min =
  1077. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1078. mpll->pll_out_max =
  1079. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1080. /* ??? */
  1081. if (mpll->pll_out_min == 0) {
  1082. if (ASIC_IS_AVIVO(rdev))
  1083. mpll->pll_out_min = 64800;
  1084. else
  1085. mpll->pll_out_min = 20000;
  1086. }
  1087. mpll->pll_in_min =
  1088. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1089. mpll->pll_in_max =
  1090. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1091. rdev->clock.default_sclk =
  1092. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1093. rdev->clock.default_mclk =
  1094. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1095. if (ASIC_IS_DCE4(rdev)) {
  1096. rdev->clock.default_dispclk =
  1097. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1098. if (rdev->clock.default_dispclk == 0) {
  1099. if (ASIC_IS_DCE5(rdev))
  1100. rdev->clock.default_dispclk = 54000; /* 540 Mhz */
  1101. else
  1102. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1103. }
  1104. rdev->clock.dp_extclk =
  1105. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1106. }
  1107. *dcpll = *p1pll;
  1108. return true;
  1109. }
  1110. return false;
  1111. }
  1112. union igp_info {
  1113. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1114. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1115. };
  1116. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1117. {
  1118. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1119. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1120. union igp_info *igp_info;
  1121. u8 frev, crev;
  1122. u16 data_offset;
  1123. /* sideport is AMD only */
  1124. if (rdev->family == CHIP_RS600)
  1125. return false;
  1126. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1127. &frev, &crev, &data_offset)) {
  1128. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1129. data_offset);
  1130. switch (crev) {
  1131. case 1:
  1132. if (igp_info->info.ulBootUpMemoryClock)
  1133. return true;
  1134. break;
  1135. case 2:
  1136. if (igp_info->info_2.ulBootUpSidePortClock)
  1137. return true;
  1138. break;
  1139. default:
  1140. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1141. break;
  1142. }
  1143. }
  1144. return false;
  1145. }
  1146. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1147. struct radeon_encoder_int_tmds *tmds)
  1148. {
  1149. struct drm_device *dev = encoder->base.dev;
  1150. struct radeon_device *rdev = dev->dev_private;
  1151. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1152. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1153. uint16_t data_offset;
  1154. struct _ATOM_TMDS_INFO *tmds_info;
  1155. uint8_t frev, crev;
  1156. uint16_t maxfreq;
  1157. int i;
  1158. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1159. &frev, &crev, &data_offset)) {
  1160. tmds_info =
  1161. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1162. data_offset);
  1163. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1164. for (i = 0; i < 4; i++) {
  1165. tmds->tmds_pll[i].freq =
  1166. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1167. tmds->tmds_pll[i].value =
  1168. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1169. tmds->tmds_pll[i].value |=
  1170. (tmds_info->asMiscInfo[i].
  1171. ucPLL_VCO_Gain & 0x3f) << 6;
  1172. tmds->tmds_pll[i].value |=
  1173. (tmds_info->asMiscInfo[i].
  1174. ucPLL_DutyCycle & 0xf) << 12;
  1175. tmds->tmds_pll[i].value |=
  1176. (tmds_info->asMiscInfo[i].
  1177. ucPLL_VoltageSwing & 0xf) << 16;
  1178. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1179. tmds->tmds_pll[i].freq,
  1180. tmds->tmds_pll[i].value);
  1181. if (maxfreq == tmds->tmds_pll[i].freq) {
  1182. tmds->tmds_pll[i].freq = 0xffffffff;
  1183. break;
  1184. }
  1185. }
  1186. return true;
  1187. }
  1188. return false;
  1189. }
  1190. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1191. struct radeon_atom_ss *ss,
  1192. int id)
  1193. {
  1194. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1195. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1196. uint16_t data_offset, size;
  1197. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1198. uint8_t frev, crev;
  1199. int i, num_indices;
  1200. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1201. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1202. &frev, &crev, &data_offset)) {
  1203. ss_info =
  1204. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1205. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1206. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1207. for (i = 0; i < num_indices; i++) {
  1208. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1209. ss->percentage =
  1210. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1211. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1212. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1213. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1214. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1215. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1216. return true;
  1217. }
  1218. }
  1219. }
  1220. return false;
  1221. }
  1222. static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
  1223. struct radeon_atom_ss *ss,
  1224. int id)
  1225. {
  1226. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1227. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1228. u16 data_offset, size;
  1229. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
  1230. u8 frev, crev;
  1231. u16 percentage = 0, rate = 0;
  1232. /* get any igp specific overrides */
  1233. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1234. &frev, &crev, &data_offset)) {
  1235. igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
  1236. (mode_info->atom_context->bios + data_offset);
  1237. switch (id) {
  1238. case ASIC_INTERNAL_SS_ON_TMDS:
  1239. percentage = le16_to_cpu(igp_info->usDVISSPercentage);
  1240. rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
  1241. break;
  1242. case ASIC_INTERNAL_SS_ON_HDMI:
  1243. percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
  1244. rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
  1245. break;
  1246. case ASIC_INTERNAL_SS_ON_LVDS:
  1247. percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
  1248. rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
  1249. break;
  1250. }
  1251. if (percentage)
  1252. ss->percentage = percentage;
  1253. if (rate)
  1254. ss->rate = rate;
  1255. }
  1256. }
  1257. union asic_ss_info {
  1258. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1259. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1260. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1261. };
  1262. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1263. struct radeon_atom_ss *ss,
  1264. int id, u32 clock)
  1265. {
  1266. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1267. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1268. uint16_t data_offset, size;
  1269. union asic_ss_info *ss_info;
  1270. uint8_t frev, crev;
  1271. int i, num_indices;
  1272. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1273. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1274. &frev, &crev, &data_offset)) {
  1275. ss_info =
  1276. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1277. switch (frev) {
  1278. case 1:
  1279. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1280. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1281. for (i = 0; i < num_indices; i++) {
  1282. if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
  1283. (clock <= ss_info->info.asSpreadSpectrum[i].ulTargetClockRange)) {
  1284. ss->percentage =
  1285. le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1286. ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1287. ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
  1288. return true;
  1289. }
  1290. }
  1291. break;
  1292. case 2:
  1293. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1294. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1295. for (i = 0; i < num_indices; i++) {
  1296. if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
  1297. (clock <= ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange)) {
  1298. ss->percentage =
  1299. le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1300. ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1301. ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1302. return true;
  1303. }
  1304. }
  1305. break;
  1306. case 3:
  1307. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1308. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1309. for (i = 0; i < num_indices; i++) {
  1310. if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
  1311. (clock <= ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange)) {
  1312. ss->percentage =
  1313. le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1314. ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1315. ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1316. if (rdev->flags & RADEON_IS_IGP)
  1317. radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
  1318. return true;
  1319. }
  1320. }
  1321. break;
  1322. default:
  1323. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1324. break;
  1325. }
  1326. }
  1327. return false;
  1328. }
  1329. union lvds_info {
  1330. struct _ATOM_LVDS_INFO info;
  1331. struct _ATOM_LVDS_INFO_V12 info_12;
  1332. };
  1333. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1334. radeon_encoder
  1335. *encoder)
  1336. {
  1337. struct drm_device *dev = encoder->base.dev;
  1338. struct radeon_device *rdev = dev->dev_private;
  1339. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1340. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1341. uint16_t data_offset, misc;
  1342. union lvds_info *lvds_info;
  1343. uint8_t frev, crev;
  1344. struct radeon_encoder_atom_dig *lvds = NULL;
  1345. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1346. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1347. &frev, &crev, &data_offset)) {
  1348. lvds_info =
  1349. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1350. lvds =
  1351. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1352. if (!lvds)
  1353. return NULL;
  1354. lvds->native_mode.clock =
  1355. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1356. lvds->native_mode.hdisplay =
  1357. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1358. lvds->native_mode.vdisplay =
  1359. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1360. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1361. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1362. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1363. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1364. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1365. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1366. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1367. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1368. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1369. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1370. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1371. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1372. lvds->panel_pwr_delay =
  1373. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1374. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1375. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1376. if (misc & ATOM_VSYNC_POLARITY)
  1377. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1378. if (misc & ATOM_HSYNC_POLARITY)
  1379. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1380. if (misc & ATOM_COMPOSITESYNC)
  1381. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1382. if (misc & ATOM_INTERLACE)
  1383. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1384. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1385. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1386. lvds->native_mode.width_mm = lvds_info->info.sLCDTiming.usImageHSize;
  1387. lvds->native_mode.height_mm = lvds_info->info.sLCDTiming.usImageVSize;
  1388. /* set crtc values */
  1389. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1390. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1391. encoder->native_mode = lvds->native_mode;
  1392. if (encoder_enum == 2)
  1393. lvds->linkb = true;
  1394. else
  1395. lvds->linkb = false;
  1396. /* parse the lcd record table */
  1397. if (lvds_info->info.usModePatchTableOffset) {
  1398. ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
  1399. ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
  1400. bool bad_record = false;
  1401. u8 *record = (u8 *)(mode_info->atom_context->bios +
  1402. data_offset +
  1403. lvds_info->info.usModePatchTableOffset);
  1404. while (*record != ATOM_RECORD_END_TYPE) {
  1405. switch (*record) {
  1406. case LCD_MODE_PATCH_RECORD_MODE_TYPE:
  1407. record += sizeof(ATOM_PATCH_RECORD_MODE);
  1408. break;
  1409. case LCD_RTS_RECORD_TYPE:
  1410. record += sizeof(ATOM_LCD_RTS_RECORD);
  1411. break;
  1412. case LCD_CAP_RECORD_TYPE:
  1413. record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
  1414. break;
  1415. case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
  1416. fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
  1417. if (fake_edid_record->ucFakeEDIDLength) {
  1418. struct edid *edid;
  1419. int edid_size =
  1420. max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
  1421. edid = kmalloc(edid_size, GFP_KERNEL);
  1422. if (edid) {
  1423. memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
  1424. fake_edid_record->ucFakeEDIDLength);
  1425. if (drm_edid_is_valid(edid))
  1426. rdev->mode_info.bios_hardcoded_edid = edid;
  1427. else
  1428. kfree(edid);
  1429. }
  1430. }
  1431. record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
  1432. break;
  1433. case LCD_PANEL_RESOLUTION_RECORD_TYPE:
  1434. panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
  1435. lvds->native_mode.width_mm = panel_res_record->usHSize;
  1436. lvds->native_mode.height_mm = panel_res_record->usVSize;
  1437. record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
  1438. break;
  1439. default:
  1440. DRM_ERROR("Bad LCD record %d\n", *record);
  1441. bad_record = true;
  1442. break;
  1443. }
  1444. if (bad_record)
  1445. break;
  1446. }
  1447. }
  1448. }
  1449. return lvds;
  1450. }
  1451. struct radeon_encoder_primary_dac *
  1452. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1453. {
  1454. struct drm_device *dev = encoder->base.dev;
  1455. struct radeon_device *rdev = dev->dev_private;
  1456. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1457. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1458. uint16_t data_offset;
  1459. struct _COMPASSIONATE_DATA *dac_info;
  1460. uint8_t frev, crev;
  1461. uint8_t bg, dac;
  1462. struct radeon_encoder_primary_dac *p_dac = NULL;
  1463. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1464. &frev, &crev, &data_offset)) {
  1465. dac_info = (struct _COMPASSIONATE_DATA *)
  1466. (mode_info->atom_context->bios + data_offset);
  1467. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1468. if (!p_dac)
  1469. return NULL;
  1470. bg = dac_info->ucDAC1_BG_Adjustment;
  1471. dac = dac_info->ucDAC1_DAC_Adjustment;
  1472. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1473. }
  1474. return p_dac;
  1475. }
  1476. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1477. struct drm_display_mode *mode)
  1478. {
  1479. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1480. ATOM_ANALOG_TV_INFO *tv_info;
  1481. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1482. ATOM_DTD_FORMAT *dtd_timings;
  1483. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1484. u8 frev, crev;
  1485. u16 data_offset, misc;
  1486. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1487. &frev, &crev, &data_offset))
  1488. return false;
  1489. switch (crev) {
  1490. case 1:
  1491. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1492. if (index >= MAX_SUPPORTED_TV_TIMING)
  1493. return false;
  1494. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1495. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1496. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1497. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1498. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1499. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1500. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1501. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1502. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1503. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1504. mode->flags = 0;
  1505. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1506. if (misc & ATOM_VSYNC_POLARITY)
  1507. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1508. if (misc & ATOM_HSYNC_POLARITY)
  1509. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1510. if (misc & ATOM_COMPOSITESYNC)
  1511. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1512. if (misc & ATOM_INTERLACE)
  1513. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1514. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1515. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1516. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1517. if (index == 1) {
  1518. /* PAL timings appear to have wrong values for totals */
  1519. mode->crtc_htotal -= 1;
  1520. mode->crtc_vtotal -= 1;
  1521. }
  1522. break;
  1523. case 2:
  1524. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1525. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1526. return false;
  1527. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1528. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1529. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1530. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1531. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1532. le16_to_cpu(dtd_timings->usHSyncOffset);
  1533. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1534. le16_to_cpu(dtd_timings->usHSyncWidth);
  1535. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1536. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1537. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1538. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1539. le16_to_cpu(dtd_timings->usVSyncOffset);
  1540. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1541. le16_to_cpu(dtd_timings->usVSyncWidth);
  1542. mode->flags = 0;
  1543. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1544. if (misc & ATOM_VSYNC_POLARITY)
  1545. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1546. if (misc & ATOM_HSYNC_POLARITY)
  1547. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1548. if (misc & ATOM_COMPOSITESYNC)
  1549. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1550. if (misc & ATOM_INTERLACE)
  1551. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1552. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1553. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1554. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1555. break;
  1556. }
  1557. return true;
  1558. }
  1559. enum radeon_tv_std
  1560. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1561. {
  1562. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1563. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1564. uint16_t data_offset;
  1565. uint8_t frev, crev;
  1566. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1567. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1568. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1569. &frev, &crev, &data_offset)) {
  1570. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1571. (mode_info->atom_context->bios + data_offset);
  1572. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1573. case ATOM_TV_NTSC:
  1574. tv_std = TV_STD_NTSC;
  1575. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1576. break;
  1577. case ATOM_TV_NTSCJ:
  1578. tv_std = TV_STD_NTSC_J;
  1579. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1580. break;
  1581. case ATOM_TV_PAL:
  1582. tv_std = TV_STD_PAL;
  1583. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1584. break;
  1585. case ATOM_TV_PALM:
  1586. tv_std = TV_STD_PAL_M;
  1587. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1588. break;
  1589. case ATOM_TV_PALN:
  1590. tv_std = TV_STD_PAL_N;
  1591. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1592. break;
  1593. case ATOM_TV_PALCN:
  1594. tv_std = TV_STD_PAL_CN;
  1595. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1596. break;
  1597. case ATOM_TV_PAL60:
  1598. tv_std = TV_STD_PAL_60;
  1599. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1600. break;
  1601. case ATOM_TV_SECAM:
  1602. tv_std = TV_STD_SECAM;
  1603. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1604. break;
  1605. default:
  1606. tv_std = TV_STD_NTSC;
  1607. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1608. break;
  1609. }
  1610. }
  1611. return tv_std;
  1612. }
  1613. struct radeon_encoder_tv_dac *
  1614. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1615. {
  1616. struct drm_device *dev = encoder->base.dev;
  1617. struct radeon_device *rdev = dev->dev_private;
  1618. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1619. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1620. uint16_t data_offset;
  1621. struct _COMPASSIONATE_DATA *dac_info;
  1622. uint8_t frev, crev;
  1623. uint8_t bg, dac;
  1624. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1625. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1626. &frev, &crev, &data_offset)) {
  1627. dac_info = (struct _COMPASSIONATE_DATA *)
  1628. (mode_info->atom_context->bios + data_offset);
  1629. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1630. if (!tv_dac)
  1631. return NULL;
  1632. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1633. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1634. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1635. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1636. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1637. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1638. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1639. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1640. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1641. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1642. }
  1643. return tv_dac;
  1644. }
  1645. static const char *thermal_controller_names[] = {
  1646. "NONE",
  1647. "lm63",
  1648. "adm1032",
  1649. "adm1030",
  1650. "max6649",
  1651. "lm64",
  1652. "f75375",
  1653. "asc7xxx",
  1654. };
  1655. static const char *pp_lib_thermal_controller_names[] = {
  1656. "NONE",
  1657. "lm63",
  1658. "adm1032",
  1659. "adm1030",
  1660. "max6649",
  1661. "lm64",
  1662. "f75375",
  1663. "RV6xx",
  1664. "RV770",
  1665. "adt7473",
  1666. "NONE",
  1667. "External GPIO",
  1668. "Evergreen",
  1669. "emc2103",
  1670. "Sumo",
  1671. "Northern Islands",
  1672. };
  1673. union power_info {
  1674. struct _ATOM_POWERPLAY_INFO info;
  1675. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1676. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1677. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1678. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1679. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1680. };
  1681. union pplib_clock_info {
  1682. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1683. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1684. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1685. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1686. };
  1687. union pplib_power_state {
  1688. struct _ATOM_PPLIB_STATE v1;
  1689. struct _ATOM_PPLIB_STATE_V2 v2;
  1690. };
  1691. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1692. int state_index,
  1693. u32 misc, u32 misc2)
  1694. {
  1695. rdev->pm.power_state[state_index].misc = misc;
  1696. rdev->pm.power_state[state_index].misc2 = misc2;
  1697. /* order matters! */
  1698. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1699. rdev->pm.power_state[state_index].type =
  1700. POWER_STATE_TYPE_POWERSAVE;
  1701. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1702. rdev->pm.power_state[state_index].type =
  1703. POWER_STATE_TYPE_BATTERY;
  1704. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1705. rdev->pm.power_state[state_index].type =
  1706. POWER_STATE_TYPE_BATTERY;
  1707. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1708. rdev->pm.power_state[state_index].type =
  1709. POWER_STATE_TYPE_BALANCED;
  1710. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1711. rdev->pm.power_state[state_index].type =
  1712. POWER_STATE_TYPE_PERFORMANCE;
  1713. rdev->pm.power_state[state_index].flags &=
  1714. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1715. }
  1716. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1717. rdev->pm.power_state[state_index].type =
  1718. POWER_STATE_TYPE_BALANCED;
  1719. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1720. rdev->pm.power_state[state_index].type =
  1721. POWER_STATE_TYPE_DEFAULT;
  1722. rdev->pm.default_power_state_index = state_index;
  1723. rdev->pm.power_state[state_index].default_clock_mode =
  1724. &rdev->pm.power_state[state_index].clock_info[0];
  1725. } else if (state_index == 0) {
  1726. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1727. RADEON_PM_MODE_NO_DISPLAY;
  1728. }
  1729. }
  1730. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1731. {
  1732. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1733. u32 misc, misc2 = 0;
  1734. int num_modes = 0, i;
  1735. int state_index = 0;
  1736. struct radeon_i2c_bus_rec i2c_bus;
  1737. union power_info *power_info;
  1738. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1739. u16 data_offset;
  1740. u8 frev, crev;
  1741. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1742. &frev, &crev, &data_offset))
  1743. return state_index;
  1744. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1745. /* add the i2c bus for thermal/fan chip */
  1746. if (power_info->info.ucOverdriveThermalController > 0) {
  1747. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1748. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1749. power_info->info.ucOverdriveControllerAddress >> 1);
  1750. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1751. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1752. if (rdev->pm.i2c_bus) {
  1753. struct i2c_board_info info = { };
  1754. const char *name = thermal_controller_names[power_info->info.
  1755. ucOverdriveThermalController];
  1756. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1757. strlcpy(info.type, name, sizeof(info.type));
  1758. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1759. }
  1760. }
  1761. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1762. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1763. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1764. /* last mode is usually default, array is low to high */
  1765. for (i = 0; i < num_modes; i++) {
  1766. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1767. switch (frev) {
  1768. case 1:
  1769. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1770. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1771. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1772. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1773. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1774. /* skip invalid modes */
  1775. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1776. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1777. continue;
  1778. rdev->pm.power_state[state_index].pcie_lanes =
  1779. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1780. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1781. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1782. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1783. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1784. VOLTAGE_GPIO;
  1785. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1786. radeon_lookup_gpio(rdev,
  1787. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1788. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1789. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1790. true;
  1791. else
  1792. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1793. false;
  1794. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1795. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1796. VOLTAGE_VDDC;
  1797. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1798. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1799. }
  1800. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1801. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1802. state_index++;
  1803. break;
  1804. case 2:
  1805. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1806. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1807. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1808. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1809. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1810. /* skip invalid modes */
  1811. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1812. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1813. continue;
  1814. rdev->pm.power_state[state_index].pcie_lanes =
  1815. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1816. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1817. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1818. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1819. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1820. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1821. VOLTAGE_GPIO;
  1822. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1823. radeon_lookup_gpio(rdev,
  1824. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1825. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1826. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1827. true;
  1828. else
  1829. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1830. false;
  1831. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1832. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1833. VOLTAGE_VDDC;
  1834. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1835. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1836. }
  1837. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1838. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1839. state_index++;
  1840. break;
  1841. case 3:
  1842. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1843. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1844. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1845. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1846. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1847. /* skip invalid modes */
  1848. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1849. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1850. continue;
  1851. rdev->pm.power_state[state_index].pcie_lanes =
  1852. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1853. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1854. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1855. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1856. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1857. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1858. VOLTAGE_GPIO;
  1859. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1860. radeon_lookup_gpio(rdev,
  1861. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1862. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1863. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1864. true;
  1865. else
  1866. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1867. false;
  1868. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1869. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1870. VOLTAGE_VDDC;
  1871. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1872. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1873. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1874. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1875. true;
  1876. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1877. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1878. }
  1879. }
  1880. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1881. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1882. state_index++;
  1883. break;
  1884. }
  1885. }
  1886. /* last mode is usually default */
  1887. if (rdev->pm.default_power_state_index == -1) {
  1888. rdev->pm.power_state[state_index - 1].type =
  1889. POWER_STATE_TYPE_DEFAULT;
  1890. rdev->pm.default_power_state_index = state_index - 1;
  1891. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1892. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1893. rdev->pm.power_state[state_index].flags &=
  1894. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1895. rdev->pm.power_state[state_index].misc = 0;
  1896. rdev->pm.power_state[state_index].misc2 = 0;
  1897. }
  1898. return state_index;
  1899. }
  1900. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  1901. ATOM_PPLIB_THERMALCONTROLLER *controller)
  1902. {
  1903. struct radeon_i2c_bus_rec i2c_bus;
  1904. /* add the i2c bus for thermal/fan chip */
  1905. if (controller->ucType > 0) {
  1906. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1907. DRM_INFO("Internal thermal controller %s fan control\n",
  1908. (controller->ucFanParameters &
  1909. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1910. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1911. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1912. DRM_INFO("Internal thermal controller %s fan control\n",
  1913. (controller->ucFanParameters &
  1914. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1915. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1916. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  1917. DRM_INFO("Internal thermal controller %s fan control\n",
  1918. (controller->ucFanParameters &
  1919. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1920. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  1921. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  1922. DRM_INFO("Internal thermal controller %s fan control\n",
  1923. (controller->ucFanParameters &
  1924. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1925. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  1926. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  1927. DRM_INFO("Internal thermal controller %s fan control\n",
  1928. (controller->ucFanParameters &
  1929. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1930. rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
  1931. } else if ((controller->ucType ==
  1932. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1933. (controller->ucType ==
  1934. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
  1935. (controller->ucType ==
  1936. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
  1937. DRM_INFO("Special thermal controller config\n");
  1938. } else {
  1939. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1940. pp_lib_thermal_controller_names[controller->ucType],
  1941. controller->ucI2cAddress >> 1,
  1942. (controller->ucFanParameters &
  1943. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1944. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1945. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1946. if (rdev->pm.i2c_bus) {
  1947. struct i2c_board_info info = { };
  1948. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  1949. info.addr = controller->ucI2cAddress >> 1;
  1950. strlcpy(info.type, name, sizeof(info.type));
  1951. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1952. }
  1953. }
  1954. }
  1955. }
  1956. static u16 radeon_atombios_get_default_vddc(struct radeon_device *rdev)
  1957. {
  1958. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1959. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  1960. u8 frev, crev;
  1961. u16 data_offset;
  1962. union firmware_info *firmware_info;
  1963. u16 vddc = 0;
  1964. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1965. &frev, &crev, &data_offset)) {
  1966. firmware_info =
  1967. (union firmware_info *)(mode_info->atom_context->bios +
  1968. data_offset);
  1969. vddc = firmware_info->info_14.usBootUpVDDCVoltage;
  1970. }
  1971. return vddc;
  1972. }
  1973. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1974. int state_index, int mode_index,
  1975. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  1976. {
  1977. int j;
  1978. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1979. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  1980. u16 vddc = radeon_atombios_get_default_vddc(rdev);
  1981. rdev->pm.power_state[state_index].misc = misc;
  1982. rdev->pm.power_state[state_index].misc2 = misc2;
  1983. rdev->pm.power_state[state_index].pcie_lanes =
  1984. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  1985. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  1986. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  1987. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  1988. rdev->pm.power_state[state_index].type =
  1989. POWER_STATE_TYPE_BATTERY;
  1990. break;
  1991. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  1992. rdev->pm.power_state[state_index].type =
  1993. POWER_STATE_TYPE_BALANCED;
  1994. break;
  1995. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  1996. rdev->pm.power_state[state_index].type =
  1997. POWER_STATE_TYPE_PERFORMANCE;
  1998. break;
  1999. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  2000. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  2001. rdev->pm.power_state[state_index].type =
  2002. POWER_STATE_TYPE_PERFORMANCE;
  2003. break;
  2004. }
  2005. rdev->pm.power_state[state_index].flags = 0;
  2006. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  2007. rdev->pm.power_state[state_index].flags |=
  2008. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2009. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2010. rdev->pm.power_state[state_index].type =
  2011. POWER_STATE_TYPE_DEFAULT;
  2012. rdev->pm.default_power_state_index = state_index;
  2013. rdev->pm.power_state[state_index].default_clock_mode =
  2014. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  2015. if (ASIC_IS_DCE5(rdev)) {
  2016. /* NI chips post without MC ucode, so default clocks are strobe mode only */
  2017. rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
  2018. rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
  2019. rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
  2020. } else {
  2021. /* patch the table values with the default slck/mclk from firmware info */
  2022. for (j = 0; j < mode_index; j++) {
  2023. rdev->pm.power_state[state_index].clock_info[j].mclk =
  2024. rdev->clock.default_mclk;
  2025. rdev->pm.power_state[state_index].clock_info[j].sclk =
  2026. rdev->clock.default_sclk;
  2027. if (vddc)
  2028. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  2029. vddc;
  2030. }
  2031. }
  2032. }
  2033. }
  2034. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  2035. int state_index, int mode_index,
  2036. union pplib_clock_info *clock_info)
  2037. {
  2038. u32 sclk, mclk;
  2039. if (rdev->flags & RADEON_IS_IGP) {
  2040. if (rdev->family >= CHIP_PALM) {
  2041. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2042. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2043. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2044. } else {
  2045. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  2046. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  2047. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2048. }
  2049. } else if (ASIC_IS_DCE4(rdev)) {
  2050. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  2051. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  2052. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  2053. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  2054. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2055. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2056. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2057. VOLTAGE_SW;
  2058. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2059. clock_info->evergreen.usVDDC;
  2060. } else {
  2061. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  2062. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  2063. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  2064. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  2065. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2066. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2067. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2068. VOLTAGE_SW;
  2069. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2070. clock_info->r600.usVDDC;
  2071. }
  2072. if (rdev->flags & RADEON_IS_IGP) {
  2073. /* skip invalid modes */
  2074. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  2075. return false;
  2076. } else {
  2077. /* skip invalid modes */
  2078. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  2079. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  2080. return false;
  2081. }
  2082. return true;
  2083. }
  2084. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  2085. {
  2086. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2087. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2088. union pplib_power_state *power_state;
  2089. int i, j;
  2090. int state_index = 0, mode_index = 0;
  2091. union pplib_clock_info *clock_info;
  2092. bool valid;
  2093. union power_info *power_info;
  2094. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2095. u16 data_offset;
  2096. u8 frev, crev;
  2097. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2098. &frev, &crev, &data_offset))
  2099. return state_index;
  2100. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2101. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2102. /* first mode is usually default, followed by low to high */
  2103. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  2104. mode_index = 0;
  2105. power_state = (union pplib_power_state *)
  2106. (mode_info->atom_context->bios + data_offset +
  2107. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  2108. i * power_info->pplib.ucStateEntrySize);
  2109. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2110. (mode_info->atom_context->bios + data_offset +
  2111. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  2112. (power_state->v1.ucNonClockStateIndex *
  2113. power_info->pplib.ucNonClockSize));
  2114. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  2115. clock_info = (union pplib_clock_info *)
  2116. (mode_info->atom_context->bios + data_offset +
  2117. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  2118. (power_state->v1.ucClockStateIndices[j] *
  2119. power_info->pplib.ucClockInfoSize));
  2120. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2121. state_index, mode_index,
  2122. clock_info);
  2123. if (valid)
  2124. mode_index++;
  2125. }
  2126. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2127. if (mode_index) {
  2128. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2129. non_clock_info);
  2130. state_index++;
  2131. }
  2132. }
  2133. /* if multiple clock modes, mark the lowest as no display */
  2134. for (i = 0; i < state_index; i++) {
  2135. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2136. rdev->pm.power_state[i].clock_info[0].flags |=
  2137. RADEON_PM_MODE_NO_DISPLAY;
  2138. }
  2139. /* first mode is usually default */
  2140. if (rdev->pm.default_power_state_index == -1) {
  2141. rdev->pm.power_state[0].type =
  2142. POWER_STATE_TYPE_DEFAULT;
  2143. rdev->pm.default_power_state_index = 0;
  2144. rdev->pm.power_state[0].default_clock_mode =
  2145. &rdev->pm.power_state[0].clock_info[0];
  2146. }
  2147. return state_index;
  2148. }
  2149. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2150. {
  2151. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2152. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2153. union pplib_power_state *power_state;
  2154. int i, j, non_clock_array_index, clock_array_index;
  2155. int state_index = 0, mode_index = 0;
  2156. union pplib_clock_info *clock_info;
  2157. struct StateArray *state_array;
  2158. struct ClockInfoArray *clock_info_array;
  2159. struct NonClockInfoArray *non_clock_info_array;
  2160. bool valid;
  2161. union power_info *power_info;
  2162. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2163. u16 data_offset;
  2164. u8 frev, crev;
  2165. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2166. &frev, &crev, &data_offset))
  2167. return state_index;
  2168. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2169. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2170. state_array = (struct StateArray *)
  2171. (mode_info->atom_context->bios + data_offset +
  2172. power_info->pplib.usStateArrayOffset);
  2173. clock_info_array = (struct ClockInfoArray *)
  2174. (mode_info->atom_context->bios + data_offset +
  2175. power_info->pplib.usClockInfoArrayOffset);
  2176. non_clock_info_array = (struct NonClockInfoArray *)
  2177. (mode_info->atom_context->bios + data_offset +
  2178. power_info->pplib.usNonClockInfoArrayOffset);
  2179. for (i = 0; i < state_array->ucNumEntries; i++) {
  2180. mode_index = 0;
  2181. power_state = (union pplib_power_state *)&state_array->states[i];
  2182. /* XXX this might be an inagua bug... */
  2183. non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
  2184. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2185. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2186. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2187. clock_array_index = power_state->v2.clockInfoIndex[j];
  2188. /* XXX this might be an inagua bug... */
  2189. if (clock_array_index >= clock_info_array->ucNumEntries)
  2190. continue;
  2191. clock_info = (union pplib_clock_info *)
  2192. &clock_info_array->clockInfo[clock_array_index];
  2193. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2194. state_index, mode_index,
  2195. clock_info);
  2196. if (valid)
  2197. mode_index++;
  2198. }
  2199. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2200. if (mode_index) {
  2201. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2202. non_clock_info);
  2203. state_index++;
  2204. }
  2205. }
  2206. /* if multiple clock modes, mark the lowest as no display */
  2207. for (i = 0; i < state_index; i++) {
  2208. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2209. rdev->pm.power_state[i].clock_info[0].flags |=
  2210. RADEON_PM_MODE_NO_DISPLAY;
  2211. }
  2212. /* first mode is usually default */
  2213. if (rdev->pm.default_power_state_index == -1) {
  2214. rdev->pm.power_state[0].type =
  2215. POWER_STATE_TYPE_DEFAULT;
  2216. rdev->pm.default_power_state_index = 0;
  2217. rdev->pm.power_state[0].default_clock_mode =
  2218. &rdev->pm.power_state[0].clock_info[0];
  2219. }
  2220. return state_index;
  2221. }
  2222. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2223. {
  2224. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2225. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2226. u16 data_offset;
  2227. u8 frev, crev;
  2228. int state_index = 0;
  2229. rdev->pm.default_power_state_index = -1;
  2230. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2231. &frev, &crev, &data_offset)) {
  2232. switch (frev) {
  2233. case 1:
  2234. case 2:
  2235. case 3:
  2236. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2237. break;
  2238. case 4:
  2239. case 5:
  2240. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2241. break;
  2242. case 6:
  2243. state_index = radeon_atombios_parse_power_table_6(rdev);
  2244. break;
  2245. default:
  2246. break;
  2247. }
  2248. } else {
  2249. /* add the default mode */
  2250. rdev->pm.power_state[state_index].type =
  2251. POWER_STATE_TYPE_DEFAULT;
  2252. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2253. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2254. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2255. rdev->pm.power_state[state_index].default_clock_mode =
  2256. &rdev->pm.power_state[state_index].clock_info[0];
  2257. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2258. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2259. rdev->pm.default_power_state_index = state_index;
  2260. rdev->pm.power_state[state_index].flags = 0;
  2261. state_index++;
  2262. }
  2263. rdev->pm.num_power_states = state_index;
  2264. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2265. rdev->pm.current_clock_mode_index = 0;
  2266. rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2267. }
  2268. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2269. {
  2270. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2271. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2272. args.ucEnable = enable;
  2273. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2274. }
  2275. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2276. {
  2277. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2278. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2279. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2280. return args.ulReturnEngineClock;
  2281. }
  2282. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2283. {
  2284. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2285. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2286. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2287. return args.ulReturnMemoryClock;
  2288. }
  2289. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2290. uint32_t eng_clock)
  2291. {
  2292. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2293. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2294. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  2295. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2296. }
  2297. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2298. uint32_t mem_clock)
  2299. {
  2300. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2301. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2302. if (rdev->flags & RADEON_IS_IGP)
  2303. return;
  2304. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  2305. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2306. }
  2307. union set_voltage {
  2308. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2309. struct _SET_VOLTAGE_PARAMETERS v1;
  2310. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2311. };
  2312. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
  2313. {
  2314. union set_voltage args;
  2315. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2316. u8 frev, crev, volt_index = level;
  2317. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2318. return;
  2319. switch (crev) {
  2320. case 1:
  2321. args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2322. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2323. args.v1.ucVoltageIndex = volt_index;
  2324. break;
  2325. case 2:
  2326. args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2327. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2328. args.v2.usVoltageLevel = cpu_to_le16(level);
  2329. break;
  2330. default:
  2331. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2332. return;
  2333. }
  2334. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2335. }
  2336. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2337. {
  2338. struct radeon_device *rdev = dev->dev_private;
  2339. uint32_t bios_2_scratch, bios_6_scratch;
  2340. if (rdev->family >= CHIP_R600) {
  2341. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2342. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2343. } else {
  2344. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2345. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2346. }
  2347. /* let the bios control the backlight */
  2348. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2349. /* tell the bios not to handle mode switching */
  2350. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  2351. if (rdev->family >= CHIP_R600) {
  2352. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2353. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2354. } else {
  2355. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2356. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2357. }
  2358. }
  2359. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2360. {
  2361. uint32_t scratch_reg;
  2362. int i;
  2363. if (rdev->family >= CHIP_R600)
  2364. scratch_reg = R600_BIOS_0_SCRATCH;
  2365. else
  2366. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2367. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2368. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2369. }
  2370. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2371. {
  2372. uint32_t scratch_reg;
  2373. int i;
  2374. if (rdev->family >= CHIP_R600)
  2375. scratch_reg = R600_BIOS_0_SCRATCH;
  2376. else
  2377. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2378. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2379. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2380. }
  2381. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2382. {
  2383. struct drm_device *dev = encoder->dev;
  2384. struct radeon_device *rdev = dev->dev_private;
  2385. uint32_t bios_6_scratch;
  2386. if (rdev->family >= CHIP_R600)
  2387. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2388. else
  2389. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2390. if (lock)
  2391. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2392. else
  2393. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2394. if (rdev->family >= CHIP_R600)
  2395. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2396. else
  2397. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2398. }
  2399. /* at some point we may want to break this out into individual functions */
  2400. void
  2401. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2402. struct drm_encoder *encoder,
  2403. bool connected)
  2404. {
  2405. struct drm_device *dev = connector->dev;
  2406. struct radeon_device *rdev = dev->dev_private;
  2407. struct radeon_connector *radeon_connector =
  2408. to_radeon_connector(connector);
  2409. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2410. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2411. if (rdev->family >= CHIP_R600) {
  2412. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2413. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2414. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2415. } else {
  2416. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2417. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2418. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2419. }
  2420. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2421. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2422. if (connected) {
  2423. DRM_DEBUG_KMS("TV1 connected\n");
  2424. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2425. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2426. } else {
  2427. DRM_DEBUG_KMS("TV1 disconnected\n");
  2428. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2429. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2430. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2431. }
  2432. }
  2433. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2434. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2435. if (connected) {
  2436. DRM_DEBUG_KMS("CV connected\n");
  2437. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2438. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2439. } else {
  2440. DRM_DEBUG_KMS("CV disconnected\n");
  2441. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2442. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2443. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2444. }
  2445. }
  2446. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2447. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2448. if (connected) {
  2449. DRM_DEBUG_KMS("LCD1 connected\n");
  2450. bios_0_scratch |= ATOM_S0_LCD1;
  2451. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2452. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2453. } else {
  2454. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2455. bios_0_scratch &= ~ATOM_S0_LCD1;
  2456. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2457. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2458. }
  2459. }
  2460. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2461. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2462. if (connected) {
  2463. DRM_DEBUG_KMS("CRT1 connected\n");
  2464. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2465. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2466. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2467. } else {
  2468. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2469. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2470. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2471. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2472. }
  2473. }
  2474. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2475. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2476. if (connected) {
  2477. DRM_DEBUG_KMS("CRT2 connected\n");
  2478. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2479. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2480. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2481. } else {
  2482. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2483. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2484. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2485. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2486. }
  2487. }
  2488. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2489. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2490. if (connected) {
  2491. DRM_DEBUG_KMS("DFP1 connected\n");
  2492. bios_0_scratch |= ATOM_S0_DFP1;
  2493. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2494. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2495. } else {
  2496. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2497. bios_0_scratch &= ~ATOM_S0_DFP1;
  2498. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2499. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2500. }
  2501. }
  2502. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2503. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2504. if (connected) {
  2505. DRM_DEBUG_KMS("DFP2 connected\n");
  2506. bios_0_scratch |= ATOM_S0_DFP2;
  2507. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2508. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2509. } else {
  2510. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2511. bios_0_scratch &= ~ATOM_S0_DFP2;
  2512. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2513. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2514. }
  2515. }
  2516. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2517. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2518. if (connected) {
  2519. DRM_DEBUG_KMS("DFP3 connected\n");
  2520. bios_0_scratch |= ATOM_S0_DFP3;
  2521. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2522. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2523. } else {
  2524. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2525. bios_0_scratch &= ~ATOM_S0_DFP3;
  2526. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2527. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2528. }
  2529. }
  2530. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2531. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2532. if (connected) {
  2533. DRM_DEBUG_KMS("DFP4 connected\n");
  2534. bios_0_scratch |= ATOM_S0_DFP4;
  2535. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2536. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2537. } else {
  2538. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2539. bios_0_scratch &= ~ATOM_S0_DFP4;
  2540. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2541. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2542. }
  2543. }
  2544. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2545. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2546. if (connected) {
  2547. DRM_DEBUG_KMS("DFP5 connected\n");
  2548. bios_0_scratch |= ATOM_S0_DFP5;
  2549. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2550. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2551. } else {
  2552. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2553. bios_0_scratch &= ~ATOM_S0_DFP5;
  2554. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2555. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2556. }
  2557. }
  2558. if (rdev->family >= CHIP_R600) {
  2559. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2560. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2561. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2562. } else {
  2563. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2564. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2565. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2566. }
  2567. }
  2568. void
  2569. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2570. {
  2571. struct drm_device *dev = encoder->dev;
  2572. struct radeon_device *rdev = dev->dev_private;
  2573. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2574. uint32_t bios_3_scratch;
  2575. if (rdev->family >= CHIP_R600)
  2576. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2577. else
  2578. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2579. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2580. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2581. bios_3_scratch |= (crtc << 18);
  2582. }
  2583. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2584. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2585. bios_3_scratch |= (crtc << 24);
  2586. }
  2587. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2588. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2589. bios_3_scratch |= (crtc << 16);
  2590. }
  2591. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2592. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2593. bios_3_scratch |= (crtc << 20);
  2594. }
  2595. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2596. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2597. bios_3_scratch |= (crtc << 17);
  2598. }
  2599. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2600. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2601. bios_3_scratch |= (crtc << 19);
  2602. }
  2603. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2604. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2605. bios_3_scratch |= (crtc << 23);
  2606. }
  2607. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2608. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2609. bios_3_scratch |= (crtc << 25);
  2610. }
  2611. if (rdev->family >= CHIP_R600)
  2612. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2613. else
  2614. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2615. }
  2616. void
  2617. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2618. {
  2619. struct drm_device *dev = encoder->dev;
  2620. struct radeon_device *rdev = dev->dev_private;
  2621. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2622. uint32_t bios_2_scratch;
  2623. if (rdev->family >= CHIP_R600)
  2624. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2625. else
  2626. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2627. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2628. if (on)
  2629. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2630. else
  2631. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2632. }
  2633. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2634. if (on)
  2635. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2636. else
  2637. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2638. }
  2639. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2640. if (on)
  2641. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2642. else
  2643. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2644. }
  2645. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2646. if (on)
  2647. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2648. else
  2649. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2650. }
  2651. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2652. if (on)
  2653. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2654. else
  2655. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2656. }
  2657. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2658. if (on)
  2659. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2660. else
  2661. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2662. }
  2663. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2664. if (on)
  2665. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2666. else
  2667. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2668. }
  2669. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2670. if (on)
  2671. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2672. else
  2673. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2674. }
  2675. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2676. if (on)
  2677. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2678. else
  2679. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2680. }
  2681. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2682. if (on)
  2683. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2684. else
  2685. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2686. }
  2687. if (rdev->family >= CHIP_R600)
  2688. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2689. else
  2690. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2691. }