radeon_atombios.c 94 KB

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