radeon_atombios.c 101 KB

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