radeon_atombios.c 102 KB

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