radeon_atombios.c 103 KB

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