radeon_combios.c 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499
  1. /*
  2. * Copyright 2004 ATI Technologies Inc., Markham, Ontario
  3. * Copyright 2007-8 Advanced Micro Devices, Inc.
  4. * Copyright 2008 Red Hat Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. */
  27. #include "drmP.h"
  28. #include "radeon_drm.h"
  29. #include "radeon.h"
  30. #include "atom.h"
  31. #ifdef CONFIG_PPC_PMAC
  32. /* not sure which of these are needed */
  33. #include <asm/machdep.h>
  34. #include <asm/pmac_feature.h>
  35. #include <asm/prom.h>
  36. #include <asm/pci-bridge.h>
  37. #endif /* CONFIG_PPC_PMAC */
  38. /* from radeon_encoder.c */
  39. extern uint32_t
  40. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
  41. uint8_t dac);
  42. extern void radeon_link_encoder_connector(struct drm_device *dev);
  43. /* from radeon_connector.c */
  44. extern void
  45. radeon_add_legacy_connector(struct drm_device *dev,
  46. uint32_t connector_id,
  47. uint32_t supported_device,
  48. int connector_type,
  49. struct radeon_i2c_bus_rec *i2c_bus,
  50. uint16_t connector_object_id,
  51. struct radeon_hpd *hpd);
  52. /* from radeon_legacy_encoder.c */
  53. extern void
  54. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  55. uint32_t supported_device);
  56. /* old legacy ATI BIOS routines */
  57. /* COMBIOS table offsets */
  58. enum radeon_combios_table_offset {
  59. /* absolute offset tables */
  60. COMBIOS_ASIC_INIT_1_TABLE,
  61. COMBIOS_BIOS_SUPPORT_TABLE,
  62. COMBIOS_DAC_PROGRAMMING_TABLE,
  63. COMBIOS_MAX_COLOR_DEPTH_TABLE,
  64. COMBIOS_CRTC_INFO_TABLE,
  65. COMBIOS_PLL_INFO_TABLE,
  66. COMBIOS_TV_INFO_TABLE,
  67. COMBIOS_DFP_INFO_TABLE,
  68. COMBIOS_HW_CONFIG_INFO_TABLE,
  69. COMBIOS_MULTIMEDIA_INFO_TABLE,
  70. COMBIOS_TV_STD_PATCH_TABLE,
  71. COMBIOS_LCD_INFO_TABLE,
  72. COMBIOS_MOBILE_INFO_TABLE,
  73. COMBIOS_PLL_INIT_TABLE,
  74. COMBIOS_MEM_CONFIG_TABLE,
  75. COMBIOS_SAVE_MASK_TABLE,
  76. COMBIOS_HARDCODED_EDID_TABLE,
  77. COMBIOS_ASIC_INIT_2_TABLE,
  78. COMBIOS_CONNECTOR_INFO_TABLE,
  79. COMBIOS_DYN_CLK_1_TABLE,
  80. COMBIOS_RESERVED_MEM_TABLE,
  81. COMBIOS_EXT_TMDS_INFO_TABLE,
  82. COMBIOS_MEM_CLK_INFO_TABLE,
  83. COMBIOS_EXT_DAC_INFO_TABLE,
  84. COMBIOS_MISC_INFO_TABLE,
  85. COMBIOS_CRT_INFO_TABLE,
  86. COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE,
  87. COMBIOS_COMPONENT_VIDEO_INFO_TABLE,
  88. COMBIOS_FAN_SPEED_INFO_TABLE,
  89. COMBIOS_OVERDRIVE_INFO_TABLE,
  90. COMBIOS_OEM_INFO_TABLE,
  91. COMBIOS_DYN_CLK_2_TABLE,
  92. COMBIOS_POWER_CONNECTOR_INFO_TABLE,
  93. COMBIOS_I2C_INFO_TABLE,
  94. /* relative offset tables */
  95. COMBIOS_ASIC_INIT_3_TABLE, /* offset from misc info */
  96. COMBIOS_ASIC_INIT_4_TABLE, /* offset from misc info */
  97. COMBIOS_DETECTED_MEM_TABLE, /* offset from misc info */
  98. COMBIOS_ASIC_INIT_5_TABLE, /* offset from misc info */
  99. COMBIOS_RAM_RESET_TABLE, /* offset from mem config */
  100. COMBIOS_POWERPLAY_INFO_TABLE, /* offset from mobile info */
  101. COMBIOS_GPIO_INFO_TABLE, /* offset from mobile info */
  102. COMBIOS_LCD_DDC_INFO_TABLE, /* offset from mobile info */
  103. COMBIOS_TMDS_POWER_TABLE, /* offset from mobile info */
  104. COMBIOS_TMDS_POWER_ON_TABLE, /* offset from tmds power */
  105. COMBIOS_TMDS_POWER_OFF_TABLE, /* offset from tmds power */
  106. };
  107. enum radeon_combios_ddc {
  108. DDC_NONE_DETECTED,
  109. DDC_MONID,
  110. DDC_DVI,
  111. DDC_VGA,
  112. DDC_CRT2,
  113. DDC_LCD,
  114. DDC_GPIO,
  115. };
  116. enum radeon_combios_connector {
  117. CONNECTOR_NONE_LEGACY,
  118. CONNECTOR_PROPRIETARY_LEGACY,
  119. CONNECTOR_CRT_LEGACY,
  120. CONNECTOR_DVI_I_LEGACY,
  121. CONNECTOR_DVI_D_LEGACY,
  122. CONNECTOR_CTV_LEGACY,
  123. CONNECTOR_STV_LEGACY,
  124. CONNECTOR_UNSUPPORTED_LEGACY
  125. };
  126. const int legacy_connector_convert[] = {
  127. DRM_MODE_CONNECTOR_Unknown,
  128. DRM_MODE_CONNECTOR_DVID,
  129. DRM_MODE_CONNECTOR_VGA,
  130. DRM_MODE_CONNECTOR_DVII,
  131. DRM_MODE_CONNECTOR_DVID,
  132. DRM_MODE_CONNECTOR_Composite,
  133. DRM_MODE_CONNECTOR_SVIDEO,
  134. DRM_MODE_CONNECTOR_Unknown,
  135. };
  136. static uint16_t combios_get_table_offset(struct drm_device *dev,
  137. enum radeon_combios_table_offset table)
  138. {
  139. struct radeon_device *rdev = dev->dev_private;
  140. int rev;
  141. uint16_t offset = 0, check_offset;
  142. if (!rdev->bios)
  143. return 0;
  144. switch (table) {
  145. /* absolute offset tables */
  146. case COMBIOS_ASIC_INIT_1_TABLE:
  147. check_offset = RBIOS16(rdev->bios_header_start + 0xc);
  148. if (check_offset)
  149. offset = check_offset;
  150. break;
  151. case COMBIOS_BIOS_SUPPORT_TABLE:
  152. check_offset = RBIOS16(rdev->bios_header_start + 0x14);
  153. if (check_offset)
  154. offset = check_offset;
  155. break;
  156. case COMBIOS_DAC_PROGRAMMING_TABLE:
  157. check_offset = RBIOS16(rdev->bios_header_start + 0x2a);
  158. if (check_offset)
  159. offset = check_offset;
  160. break;
  161. case COMBIOS_MAX_COLOR_DEPTH_TABLE:
  162. check_offset = RBIOS16(rdev->bios_header_start + 0x2c);
  163. if (check_offset)
  164. offset = check_offset;
  165. break;
  166. case COMBIOS_CRTC_INFO_TABLE:
  167. check_offset = RBIOS16(rdev->bios_header_start + 0x2e);
  168. if (check_offset)
  169. offset = check_offset;
  170. break;
  171. case COMBIOS_PLL_INFO_TABLE:
  172. check_offset = RBIOS16(rdev->bios_header_start + 0x30);
  173. if (check_offset)
  174. offset = check_offset;
  175. break;
  176. case COMBIOS_TV_INFO_TABLE:
  177. check_offset = RBIOS16(rdev->bios_header_start + 0x32);
  178. if (check_offset)
  179. offset = check_offset;
  180. break;
  181. case COMBIOS_DFP_INFO_TABLE:
  182. check_offset = RBIOS16(rdev->bios_header_start + 0x34);
  183. if (check_offset)
  184. offset = check_offset;
  185. break;
  186. case COMBIOS_HW_CONFIG_INFO_TABLE:
  187. check_offset = RBIOS16(rdev->bios_header_start + 0x36);
  188. if (check_offset)
  189. offset = check_offset;
  190. break;
  191. case COMBIOS_MULTIMEDIA_INFO_TABLE:
  192. check_offset = RBIOS16(rdev->bios_header_start + 0x38);
  193. if (check_offset)
  194. offset = check_offset;
  195. break;
  196. case COMBIOS_TV_STD_PATCH_TABLE:
  197. check_offset = RBIOS16(rdev->bios_header_start + 0x3e);
  198. if (check_offset)
  199. offset = check_offset;
  200. break;
  201. case COMBIOS_LCD_INFO_TABLE:
  202. check_offset = RBIOS16(rdev->bios_header_start + 0x40);
  203. if (check_offset)
  204. offset = check_offset;
  205. break;
  206. case COMBIOS_MOBILE_INFO_TABLE:
  207. check_offset = RBIOS16(rdev->bios_header_start + 0x42);
  208. if (check_offset)
  209. offset = check_offset;
  210. break;
  211. case COMBIOS_PLL_INIT_TABLE:
  212. check_offset = RBIOS16(rdev->bios_header_start + 0x46);
  213. if (check_offset)
  214. offset = check_offset;
  215. break;
  216. case COMBIOS_MEM_CONFIG_TABLE:
  217. check_offset = RBIOS16(rdev->bios_header_start + 0x48);
  218. if (check_offset)
  219. offset = check_offset;
  220. break;
  221. case COMBIOS_SAVE_MASK_TABLE:
  222. check_offset = RBIOS16(rdev->bios_header_start + 0x4a);
  223. if (check_offset)
  224. offset = check_offset;
  225. break;
  226. case COMBIOS_HARDCODED_EDID_TABLE:
  227. check_offset = RBIOS16(rdev->bios_header_start + 0x4c);
  228. if (check_offset)
  229. offset = check_offset;
  230. break;
  231. case COMBIOS_ASIC_INIT_2_TABLE:
  232. check_offset = RBIOS16(rdev->bios_header_start + 0x4e);
  233. if (check_offset)
  234. offset = check_offset;
  235. break;
  236. case COMBIOS_CONNECTOR_INFO_TABLE:
  237. check_offset = RBIOS16(rdev->bios_header_start + 0x50);
  238. if (check_offset)
  239. offset = check_offset;
  240. break;
  241. case COMBIOS_DYN_CLK_1_TABLE:
  242. check_offset = RBIOS16(rdev->bios_header_start + 0x52);
  243. if (check_offset)
  244. offset = check_offset;
  245. break;
  246. case COMBIOS_RESERVED_MEM_TABLE:
  247. check_offset = RBIOS16(rdev->bios_header_start + 0x54);
  248. if (check_offset)
  249. offset = check_offset;
  250. break;
  251. case COMBIOS_EXT_TMDS_INFO_TABLE:
  252. check_offset = RBIOS16(rdev->bios_header_start + 0x58);
  253. if (check_offset)
  254. offset = check_offset;
  255. break;
  256. case COMBIOS_MEM_CLK_INFO_TABLE:
  257. check_offset = RBIOS16(rdev->bios_header_start + 0x5a);
  258. if (check_offset)
  259. offset = check_offset;
  260. break;
  261. case COMBIOS_EXT_DAC_INFO_TABLE:
  262. check_offset = RBIOS16(rdev->bios_header_start + 0x5c);
  263. if (check_offset)
  264. offset = check_offset;
  265. break;
  266. case COMBIOS_MISC_INFO_TABLE:
  267. check_offset = RBIOS16(rdev->bios_header_start + 0x5e);
  268. if (check_offset)
  269. offset = check_offset;
  270. break;
  271. case COMBIOS_CRT_INFO_TABLE:
  272. check_offset = RBIOS16(rdev->bios_header_start + 0x60);
  273. if (check_offset)
  274. offset = check_offset;
  275. break;
  276. case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
  277. check_offset = RBIOS16(rdev->bios_header_start + 0x62);
  278. if (check_offset)
  279. offset = check_offset;
  280. break;
  281. case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
  282. check_offset = RBIOS16(rdev->bios_header_start + 0x64);
  283. if (check_offset)
  284. offset = check_offset;
  285. break;
  286. case COMBIOS_FAN_SPEED_INFO_TABLE:
  287. check_offset = RBIOS16(rdev->bios_header_start + 0x66);
  288. if (check_offset)
  289. offset = check_offset;
  290. break;
  291. case COMBIOS_OVERDRIVE_INFO_TABLE:
  292. check_offset = RBIOS16(rdev->bios_header_start + 0x68);
  293. if (check_offset)
  294. offset = check_offset;
  295. break;
  296. case COMBIOS_OEM_INFO_TABLE:
  297. check_offset = RBIOS16(rdev->bios_header_start + 0x6a);
  298. if (check_offset)
  299. offset = check_offset;
  300. break;
  301. case COMBIOS_DYN_CLK_2_TABLE:
  302. check_offset = RBIOS16(rdev->bios_header_start + 0x6c);
  303. if (check_offset)
  304. offset = check_offset;
  305. break;
  306. case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
  307. check_offset = RBIOS16(rdev->bios_header_start + 0x6e);
  308. if (check_offset)
  309. offset = check_offset;
  310. break;
  311. case COMBIOS_I2C_INFO_TABLE:
  312. check_offset = RBIOS16(rdev->bios_header_start + 0x70);
  313. if (check_offset)
  314. offset = check_offset;
  315. break;
  316. /* relative offset tables */
  317. case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */
  318. check_offset =
  319. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  320. if (check_offset) {
  321. rev = RBIOS8(check_offset);
  322. if (rev > 0) {
  323. check_offset = RBIOS16(check_offset + 0x3);
  324. if (check_offset)
  325. offset = check_offset;
  326. }
  327. }
  328. break;
  329. case COMBIOS_ASIC_INIT_4_TABLE: /* offset from misc info */
  330. check_offset =
  331. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  332. if (check_offset) {
  333. rev = RBIOS8(check_offset);
  334. if (rev > 0) {
  335. check_offset = RBIOS16(check_offset + 0x5);
  336. if (check_offset)
  337. offset = check_offset;
  338. }
  339. }
  340. break;
  341. case COMBIOS_DETECTED_MEM_TABLE: /* offset from misc info */
  342. check_offset =
  343. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  344. if (check_offset) {
  345. rev = RBIOS8(check_offset);
  346. if (rev > 0) {
  347. check_offset = RBIOS16(check_offset + 0x7);
  348. if (check_offset)
  349. offset = check_offset;
  350. }
  351. }
  352. break;
  353. case COMBIOS_ASIC_INIT_5_TABLE: /* offset from misc info */
  354. check_offset =
  355. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  356. if (check_offset) {
  357. rev = RBIOS8(check_offset);
  358. if (rev == 2) {
  359. check_offset = RBIOS16(check_offset + 0x9);
  360. if (check_offset)
  361. offset = check_offset;
  362. }
  363. }
  364. break;
  365. case COMBIOS_RAM_RESET_TABLE: /* offset from mem config */
  366. check_offset =
  367. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  368. if (check_offset) {
  369. while (RBIOS8(check_offset++));
  370. check_offset += 2;
  371. if (check_offset)
  372. offset = check_offset;
  373. }
  374. break;
  375. case COMBIOS_POWERPLAY_INFO_TABLE: /* offset from mobile info */
  376. check_offset =
  377. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  378. if (check_offset) {
  379. check_offset = RBIOS16(check_offset + 0x11);
  380. if (check_offset)
  381. offset = check_offset;
  382. }
  383. break;
  384. case COMBIOS_GPIO_INFO_TABLE: /* offset from mobile info */
  385. check_offset =
  386. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  387. if (check_offset) {
  388. check_offset = RBIOS16(check_offset + 0x13);
  389. if (check_offset)
  390. offset = check_offset;
  391. }
  392. break;
  393. case COMBIOS_LCD_DDC_INFO_TABLE: /* offset from mobile info */
  394. check_offset =
  395. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  396. if (check_offset) {
  397. check_offset = RBIOS16(check_offset + 0x15);
  398. if (check_offset)
  399. offset = check_offset;
  400. }
  401. break;
  402. case COMBIOS_TMDS_POWER_TABLE: /* offset from mobile info */
  403. check_offset =
  404. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  405. if (check_offset) {
  406. check_offset = RBIOS16(check_offset + 0x17);
  407. if (check_offset)
  408. offset = check_offset;
  409. }
  410. break;
  411. case COMBIOS_TMDS_POWER_ON_TABLE: /* offset from tmds power */
  412. check_offset =
  413. combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
  414. if (check_offset) {
  415. check_offset = RBIOS16(check_offset + 0x2);
  416. if (check_offset)
  417. offset = check_offset;
  418. }
  419. break;
  420. case COMBIOS_TMDS_POWER_OFF_TABLE: /* offset from tmds power */
  421. check_offset =
  422. combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
  423. if (check_offset) {
  424. check_offset = RBIOS16(check_offset + 0x4);
  425. if (check_offset)
  426. offset = check_offset;
  427. }
  428. break;
  429. default:
  430. break;
  431. }
  432. return offset;
  433. }
  434. bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
  435. {
  436. int edid_info, size;
  437. struct edid *edid;
  438. unsigned char *raw;
  439. edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
  440. if (!edid_info)
  441. return false;
  442. raw = rdev->bios + edid_info;
  443. size = EDID_LENGTH * (raw[0x7e] + 1);
  444. edid = kmalloc(size, GFP_KERNEL);
  445. if (edid == NULL)
  446. return false;
  447. memcpy((unsigned char *)edid, raw, size);
  448. if (!drm_edid_is_valid(edid)) {
  449. kfree(edid);
  450. return false;
  451. }
  452. rdev->mode_info.bios_hardcoded_edid = edid;
  453. rdev->mode_info.bios_hardcoded_edid_size = size;
  454. return true;
  455. }
  456. /* this is used for atom LCDs as well */
  457. struct edid *
  458. radeon_bios_get_hardcoded_edid(struct radeon_device *rdev)
  459. {
  460. struct edid *edid;
  461. if (rdev->mode_info.bios_hardcoded_edid) {
  462. edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
  463. if (edid) {
  464. memcpy((unsigned char *)edid,
  465. (unsigned char *)rdev->mode_info.bios_hardcoded_edid,
  466. rdev->mode_info.bios_hardcoded_edid_size);
  467. return edid;
  468. }
  469. }
  470. return NULL;
  471. }
  472. static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
  473. enum radeon_combios_ddc ddc,
  474. u32 clk_mask,
  475. u32 data_mask)
  476. {
  477. struct radeon_i2c_bus_rec i2c;
  478. int ddc_line = 0;
  479. /* ddc id = mask reg
  480. * DDC_NONE_DETECTED = none
  481. * DDC_DVI = RADEON_GPIO_DVI_DDC
  482. * DDC_VGA = RADEON_GPIO_VGA_DDC
  483. * DDC_LCD = RADEON_GPIOPAD_MASK
  484. * DDC_GPIO = RADEON_MDGPIO_MASK
  485. * r1xx
  486. * DDC_MONID = RADEON_GPIO_MONID
  487. * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
  488. * r200
  489. * DDC_MONID = RADEON_GPIO_MONID
  490. * DDC_CRT2 = RADEON_GPIO_DVI_DDC
  491. * r300/r350
  492. * DDC_MONID = RADEON_GPIO_DVI_DDC
  493. * DDC_CRT2 = RADEON_GPIO_DVI_DDC
  494. * rv2xx/rv3xx
  495. * DDC_MONID = RADEON_GPIO_MONID
  496. * DDC_CRT2 = RADEON_GPIO_MONID
  497. * rs3xx/rs4xx
  498. * DDC_MONID = RADEON_GPIOPAD_MASK
  499. * DDC_CRT2 = RADEON_GPIO_MONID
  500. */
  501. switch (ddc) {
  502. case DDC_NONE_DETECTED:
  503. default:
  504. ddc_line = 0;
  505. break;
  506. case DDC_DVI:
  507. ddc_line = RADEON_GPIO_DVI_DDC;
  508. break;
  509. case DDC_VGA:
  510. ddc_line = RADEON_GPIO_VGA_DDC;
  511. break;
  512. case DDC_LCD:
  513. ddc_line = RADEON_GPIOPAD_MASK;
  514. break;
  515. case DDC_GPIO:
  516. ddc_line = RADEON_MDGPIO_MASK;
  517. break;
  518. case DDC_MONID:
  519. if (rdev->family == CHIP_RS300 ||
  520. rdev->family == CHIP_RS400 ||
  521. rdev->family == CHIP_RS480)
  522. ddc_line = RADEON_GPIOPAD_MASK;
  523. else if (rdev->family == CHIP_R300 ||
  524. rdev->family == CHIP_R350) {
  525. ddc_line = RADEON_GPIO_DVI_DDC;
  526. ddc = DDC_DVI;
  527. } else
  528. ddc_line = RADEON_GPIO_MONID;
  529. break;
  530. case DDC_CRT2:
  531. if (rdev->family == CHIP_R200 ||
  532. rdev->family == CHIP_R300 ||
  533. rdev->family == CHIP_R350) {
  534. ddc_line = RADEON_GPIO_DVI_DDC;
  535. ddc = DDC_DVI;
  536. } else if (rdev->family == CHIP_RS300 ||
  537. rdev->family == CHIP_RS400 ||
  538. rdev->family == CHIP_RS480)
  539. ddc_line = RADEON_GPIO_MONID;
  540. else if (rdev->family >= CHIP_RV350) {
  541. ddc_line = RADEON_GPIO_MONID;
  542. ddc = DDC_MONID;
  543. } else
  544. ddc_line = RADEON_GPIO_CRT2_DDC;
  545. break;
  546. }
  547. if (ddc_line == RADEON_GPIOPAD_MASK) {
  548. i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
  549. i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
  550. i2c.a_clk_reg = RADEON_GPIOPAD_A;
  551. i2c.a_data_reg = RADEON_GPIOPAD_A;
  552. i2c.en_clk_reg = RADEON_GPIOPAD_EN;
  553. i2c.en_data_reg = RADEON_GPIOPAD_EN;
  554. i2c.y_clk_reg = RADEON_GPIOPAD_Y;
  555. i2c.y_data_reg = RADEON_GPIOPAD_Y;
  556. } else if (ddc_line == RADEON_MDGPIO_MASK) {
  557. i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
  558. i2c.mask_data_reg = RADEON_MDGPIO_MASK;
  559. i2c.a_clk_reg = RADEON_MDGPIO_A;
  560. i2c.a_data_reg = RADEON_MDGPIO_A;
  561. i2c.en_clk_reg = RADEON_MDGPIO_EN;
  562. i2c.en_data_reg = RADEON_MDGPIO_EN;
  563. i2c.y_clk_reg = RADEON_MDGPIO_Y;
  564. i2c.y_data_reg = RADEON_MDGPIO_Y;
  565. } else {
  566. i2c.mask_clk_reg = ddc_line;
  567. i2c.mask_data_reg = ddc_line;
  568. i2c.a_clk_reg = ddc_line;
  569. i2c.a_data_reg = ddc_line;
  570. i2c.en_clk_reg = ddc_line;
  571. i2c.en_data_reg = ddc_line;
  572. i2c.y_clk_reg = ddc_line;
  573. i2c.y_data_reg = ddc_line;
  574. }
  575. if (clk_mask && data_mask) {
  576. /* system specific masks */
  577. i2c.mask_clk_mask = clk_mask;
  578. i2c.mask_data_mask = data_mask;
  579. i2c.a_clk_mask = clk_mask;
  580. i2c.a_data_mask = data_mask;
  581. i2c.en_clk_mask = clk_mask;
  582. i2c.en_data_mask = data_mask;
  583. i2c.y_clk_mask = clk_mask;
  584. i2c.y_data_mask = data_mask;
  585. } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
  586. (ddc_line == RADEON_MDGPIO_MASK)) {
  587. /* default gpiopad masks */
  588. i2c.mask_clk_mask = (0x20 << 8);
  589. i2c.mask_data_mask = 0x80;
  590. i2c.a_clk_mask = (0x20 << 8);
  591. i2c.a_data_mask = 0x80;
  592. i2c.en_clk_mask = (0x20 << 8);
  593. i2c.en_data_mask = 0x80;
  594. i2c.y_clk_mask = (0x20 << 8);
  595. i2c.y_data_mask = 0x80;
  596. } else {
  597. /* default masks for ddc pads */
  598. i2c.mask_clk_mask = RADEON_GPIO_EN_1;
  599. i2c.mask_data_mask = RADEON_GPIO_EN_0;
  600. i2c.a_clk_mask = RADEON_GPIO_A_1;
  601. i2c.a_data_mask = RADEON_GPIO_A_0;
  602. i2c.en_clk_mask = RADEON_GPIO_EN_1;
  603. i2c.en_data_mask = RADEON_GPIO_EN_0;
  604. i2c.y_clk_mask = RADEON_GPIO_Y_1;
  605. i2c.y_data_mask = RADEON_GPIO_Y_0;
  606. }
  607. switch (rdev->family) {
  608. case CHIP_R100:
  609. case CHIP_RV100:
  610. case CHIP_RS100:
  611. case CHIP_RV200:
  612. case CHIP_RS200:
  613. case CHIP_RS300:
  614. switch (ddc_line) {
  615. case RADEON_GPIO_DVI_DDC:
  616. i2c.hw_capable = true;
  617. break;
  618. default:
  619. i2c.hw_capable = false;
  620. break;
  621. }
  622. break;
  623. case CHIP_R200:
  624. switch (ddc_line) {
  625. case RADEON_GPIO_DVI_DDC:
  626. case RADEON_GPIO_MONID:
  627. i2c.hw_capable = true;
  628. break;
  629. default:
  630. i2c.hw_capable = false;
  631. break;
  632. }
  633. break;
  634. case CHIP_RV250:
  635. case CHIP_RV280:
  636. switch (ddc_line) {
  637. case RADEON_GPIO_VGA_DDC:
  638. case RADEON_GPIO_DVI_DDC:
  639. case RADEON_GPIO_CRT2_DDC:
  640. i2c.hw_capable = true;
  641. break;
  642. default:
  643. i2c.hw_capable = false;
  644. break;
  645. }
  646. break;
  647. case CHIP_R300:
  648. case CHIP_R350:
  649. switch (ddc_line) {
  650. case RADEON_GPIO_VGA_DDC:
  651. case RADEON_GPIO_DVI_DDC:
  652. i2c.hw_capable = true;
  653. break;
  654. default:
  655. i2c.hw_capable = false;
  656. break;
  657. }
  658. break;
  659. case CHIP_RV350:
  660. case CHIP_RV380:
  661. case CHIP_RS400:
  662. case CHIP_RS480:
  663. switch (ddc_line) {
  664. case RADEON_GPIO_VGA_DDC:
  665. case RADEON_GPIO_DVI_DDC:
  666. i2c.hw_capable = true;
  667. break;
  668. case RADEON_GPIO_MONID:
  669. /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
  670. * reliably on some pre-r4xx hardware; not sure why.
  671. */
  672. i2c.hw_capable = false;
  673. break;
  674. default:
  675. i2c.hw_capable = false;
  676. break;
  677. }
  678. break;
  679. default:
  680. i2c.hw_capable = false;
  681. break;
  682. }
  683. i2c.mm_i2c = false;
  684. i2c.i2c_id = ddc;
  685. i2c.hpd = RADEON_HPD_NONE;
  686. if (ddc_line)
  687. i2c.valid = true;
  688. else
  689. i2c.valid = false;
  690. return i2c;
  691. }
  692. void radeon_combios_i2c_init(struct radeon_device *rdev)
  693. {
  694. struct drm_device *dev = rdev->ddev;
  695. struct radeon_i2c_bus_rec i2c;
  696. /* actual hw pads
  697. * r1xx/rs2xx/rs3xx
  698. * 0x60, 0x64, 0x68, 0x6c, gpiopads, mm
  699. * r200
  700. * 0x60, 0x64, 0x68, mm
  701. * r300/r350
  702. * 0x60, 0x64, mm
  703. * rv2xx/rv3xx/rs4xx
  704. * 0x60, 0x64, 0x68, gpiopads, mm
  705. */
  706. /* 0x60 */
  707. i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  708. rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
  709. /* 0x64 */
  710. i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  711. rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
  712. /* mm i2c */
  713. i2c.valid = true;
  714. i2c.hw_capable = true;
  715. i2c.mm_i2c = true;
  716. i2c.i2c_id = 0xa0;
  717. rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
  718. if (rdev->family == CHIP_R300 ||
  719. rdev->family == CHIP_R350) {
  720. /* only 2 sw i2c pads */
  721. } else if (rdev->family == CHIP_RS300 ||
  722. rdev->family == CHIP_RS400 ||
  723. rdev->family == CHIP_RS480) {
  724. u16 offset;
  725. u8 id, blocks, clk, data;
  726. int i;
  727. /* 0x68 */
  728. i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  729. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  730. offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
  731. if (offset) {
  732. blocks = RBIOS8(offset + 2);
  733. for (i = 0; i < blocks; i++) {
  734. id = RBIOS8(offset + 3 + (i * 5) + 0);
  735. if (id == 136) {
  736. clk = RBIOS8(offset + 3 + (i * 5) + 3);
  737. data = RBIOS8(offset + 3 + (i * 5) + 4);
  738. /* gpiopad */
  739. i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
  740. (1 << clk), (1 << data));
  741. rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
  742. break;
  743. }
  744. }
  745. }
  746. } else if (rdev->family >= CHIP_R200) {
  747. /* 0x68 */
  748. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  749. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  750. } else {
  751. /* 0x68 */
  752. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  753. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  754. /* 0x6c */
  755. i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  756. rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
  757. }
  758. }
  759. bool radeon_combios_get_clock_info(struct drm_device *dev)
  760. {
  761. struct radeon_device *rdev = dev->dev_private;
  762. uint16_t pll_info;
  763. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  764. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  765. struct radeon_pll *spll = &rdev->clock.spll;
  766. struct radeon_pll *mpll = &rdev->clock.mpll;
  767. int8_t rev;
  768. uint16_t sclk, mclk;
  769. pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
  770. if (pll_info) {
  771. rev = RBIOS8(pll_info);
  772. /* pixel clocks */
  773. p1pll->reference_freq = RBIOS16(pll_info + 0xe);
  774. p1pll->reference_div = RBIOS16(pll_info + 0x10);
  775. p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
  776. p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
  777. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  778. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  779. if (rev > 9) {
  780. p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
  781. p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
  782. } else {
  783. p1pll->pll_in_min = 40;
  784. p1pll->pll_in_max = 500;
  785. }
  786. *p2pll = *p1pll;
  787. /* system clock */
  788. spll->reference_freq = RBIOS16(pll_info + 0x1a);
  789. spll->reference_div = RBIOS16(pll_info + 0x1c);
  790. spll->pll_out_min = RBIOS32(pll_info + 0x1e);
  791. spll->pll_out_max = RBIOS32(pll_info + 0x22);
  792. if (rev > 10) {
  793. spll->pll_in_min = RBIOS32(pll_info + 0x48);
  794. spll->pll_in_max = RBIOS32(pll_info + 0x4c);
  795. } else {
  796. /* ??? */
  797. spll->pll_in_min = 40;
  798. spll->pll_in_max = 500;
  799. }
  800. /* memory clock */
  801. mpll->reference_freq = RBIOS16(pll_info + 0x26);
  802. mpll->reference_div = RBIOS16(pll_info + 0x28);
  803. mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
  804. mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
  805. if (rev > 10) {
  806. mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
  807. mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
  808. } else {
  809. /* ??? */
  810. mpll->pll_in_min = 40;
  811. mpll->pll_in_max = 500;
  812. }
  813. /* default sclk/mclk */
  814. sclk = RBIOS16(pll_info + 0xa);
  815. mclk = RBIOS16(pll_info + 0x8);
  816. if (sclk == 0)
  817. sclk = 200 * 100;
  818. if (mclk == 0)
  819. mclk = 200 * 100;
  820. rdev->clock.default_sclk = sclk;
  821. rdev->clock.default_mclk = mclk;
  822. if (RBIOS32(pll_info + 0x16))
  823. rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
  824. else
  825. rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
  826. return true;
  827. }
  828. return false;
  829. }
  830. bool radeon_combios_sideport_present(struct radeon_device *rdev)
  831. {
  832. struct drm_device *dev = rdev->ddev;
  833. u16 igp_info;
  834. /* sideport is AMD only */
  835. if (rdev->family == CHIP_RS400)
  836. return false;
  837. igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
  838. if (igp_info) {
  839. if (RBIOS16(igp_info + 0x4))
  840. return true;
  841. }
  842. return false;
  843. }
  844. static const uint32_t default_primarydac_adj[CHIP_LAST] = {
  845. 0x00000808, /* r100 */
  846. 0x00000808, /* rv100 */
  847. 0x00000808, /* rs100 */
  848. 0x00000808, /* rv200 */
  849. 0x00000808, /* rs200 */
  850. 0x00000808, /* r200 */
  851. 0x00000808, /* rv250 */
  852. 0x00000000, /* rs300 */
  853. 0x00000808, /* rv280 */
  854. 0x00000808, /* r300 */
  855. 0x00000808, /* r350 */
  856. 0x00000808, /* rv350 */
  857. 0x00000808, /* rv380 */
  858. 0x00000808, /* r420 */
  859. 0x00000808, /* r423 */
  860. 0x00000808, /* rv410 */
  861. 0x00000000, /* rs400 */
  862. 0x00000000, /* rs480 */
  863. };
  864. static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
  865. struct radeon_encoder_primary_dac *p_dac)
  866. {
  867. p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
  868. return;
  869. }
  870. struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
  871. radeon_encoder
  872. *encoder)
  873. {
  874. struct drm_device *dev = encoder->base.dev;
  875. struct radeon_device *rdev = dev->dev_private;
  876. uint16_t dac_info;
  877. uint8_t rev, bg, dac;
  878. struct radeon_encoder_primary_dac *p_dac = NULL;
  879. int found = 0;
  880. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
  881. GFP_KERNEL);
  882. if (!p_dac)
  883. return NULL;
  884. /* check CRT table */
  885. dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  886. if (dac_info) {
  887. rev = RBIOS8(dac_info) & 0x3;
  888. if (rev < 2) {
  889. bg = RBIOS8(dac_info + 0x2) & 0xf;
  890. dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
  891. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  892. } else {
  893. bg = RBIOS8(dac_info + 0x2) & 0xf;
  894. dac = RBIOS8(dac_info + 0x3) & 0xf;
  895. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  896. }
  897. /* if the values are all zeros, use the table */
  898. if (p_dac->ps2_pdac_adj)
  899. found = 1;
  900. }
  901. if (!found) /* fallback to defaults */
  902. radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
  903. return p_dac;
  904. }
  905. enum radeon_tv_std
  906. radeon_combios_get_tv_info(struct radeon_device *rdev)
  907. {
  908. struct drm_device *dev = rdev->ddev;
  909. uint16_t tv_info;
  910. enum radeon_tv_std tv_std = TV_STD_NTSC;
  911. tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  912. if (tv_info) {
  913. if (RBIOS8(tv_info + 6) == 'T') {
  914. switch (RBIOS8(tv_info + 7) & 0xf) {
  915. case 1:
  916. tv_std = TV_STD_NTSC;
  917. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  918. break;
  919. case 2:
  920. tv_std = TV_STD_PAL;
  921. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  922. break;
  923. case 3:
  924. tv_std = TV_STD_PAL_M;
  925. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  926. break;
  927. case 4:
  928. tv_std = TV_STD_PAL_60;
  929. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  930. break;
  931. case 5:
  932. tv_std = TV_STD_NTSC_J;
  933. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  934. break;
  935. case 6:
  936. tv_std = TV_STD_SCART_PAL;
  937. DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
  938. break;
  939. default:
  940. tv_std = TV_STD_NTSC;
  941. DRM_DEBUG_KMS
  942. ("Unknown TV standard; defaulting to NTSC\n");
  943. break;
  944. }
  945. switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
  946. case 0:
  947. DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
  948. break;
  949. case 1:
  950. DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
  951. break;
  952. case 2:
  953. DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
  954. break;
  955. case 3:
  956. DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
  957. break;
  958. default:
  959. break;
  960. }
  961. }
  962. }
  963. return tv_std;
  964. }
  965. static const uint32_t default_tvdac_adj[CHIP_LAST] = {
  966. 0x00000000, /* r100 */
  967. 0x00280000, /* rv100 */
  968. 0x00000000, /* rs100 */
  969. 0x00880000, /* rv200 */
  970. 0x00000000, /* rs200 */
  971. 0x00000000, /* r200 */
  972. 0x00770000, /* rv250 */
  973. 0x00290000, /* rs300 */
  974. 0x00560000, /* rv280 */
  975. 0x00780000, /* r300 */
  976. 0x00770000, /* r350 */
  977. 0x00780000, /* rv350 */
  978. 0x00780000, /* rv380 */
  979. 0x01080000, /* r420 */
  980. 0x01080000, /* r423 */
  981. 0x01080000, /* rv410 */
  982. 0x00780000, /* rs400 */
  983. 0x00780000, /* rs480 */
  984. };
  985. static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
  986. struct radeon_encoder_tv_dac *tv_dac)
  987. {
  988. tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
  989. if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
  990. tv_dac->ps2_tvdac_adj = 0x00880000;
  991. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  992. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  993. return;
  994. }
  995. struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
  996. radeon_encoder
  997. *encoder)
  998. {
  999. struct drm_device *dev = encoder->base.dev;
  1000. struct radeon_device *rdev = dev->dev_private;
  1001. uint16_t dac_info;
  1002. uint8_t rev, bg, dac;
  1003. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1004. int found = 0;
  1005. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1006. if (!tv_dac)
  1007. return NULL;
  1008. /* first check TV table */
  1009. dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  1010. if (dac_info) {
  1011. rev = RBIOS8(dac_info + 0x3);
  1012. if (rev > 4) {
  1013. bg = RBIOS8(dac_info + 0xc) & 0xf;
  1014. dac = RBIOS8(dac_info + 0xd) & 0xf;
  1015. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1016. bg = RBIOS8(dac_info + 0xe) & 0xf;
  1017. dac = RBIOS8(dac_info + 0xf) & 0xf;
  1018. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1019. bg = RBIOS8(dac_info + 0x10) & 0xf;
  1020. dac = RBIOS8(dac_info + 0x11) & 0xf;
  1021. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1022. /* if the values are all zeros, use the table */
  1023. if (tv_dac->ps2_tvdac_adj)
  1024. found = 1;
  1025. } else if (rev > 1) {
  1026. bg = RBIOS8(dac_info + 0xc) & 0xf;
  1027. dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
  1028. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1029. bg = RBIOS8(dac_info + 0xd) & 0xf;
  1030. dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
  1031. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1032. bg = RBIOS8(dac_info + 0xe) & 0xf;
  1033. dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
  1034. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1035. /* if the values are all zeros, use the table */
  1036. if (tv_dac->ps2_tvdac_adj)
  1037. found = 1;
  1038. }
  1039. tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
  1040. }
  1041. if (!found) {
  1042. /* then check CRT table */
  1043. dac_info =
  1044. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  1045. if (dac_info) {
  1046. rev = RBIOS8(dac_info) & 0x3;
  1047. if (rev < 2) {
  1048. bg = RBIOS8(dac_info + 0x3) & 0xf;
  1049. dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
  1050. tv_dac->ps2_tvdac_adj =
  1051. (bg << 16) | (dac << 20);
  1052. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1053. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1054. /* if the values are all zeros, use the table */
  1055. if (tv_dac->ps2_tvdac_adj)
  1056. found = 1;
  1057. } else {
  1058. bg = RBIOS8(dac_info + 0x4) & 0xf;
  1059. dac = RBIOS8(dac_info + 0x5) & 0xf;
  1060. tv_dac->ps2_tvdac_adj =
  1061. (bg << 16) | (dac << 20);
  1062. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1063. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1064. /* if the values are all zeros, use the table */
  1065. if (tv_dac->ps2_tvdac_adj)
  1066. found = 1;
  1067. }
  1068. } else {
  1069. DRM_INFO("No TV DAC info found in BIOS\n");
  1070. }
  1071. }
  1072. if (!found) /* fallback to defaults */
  1073. radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
  1074. return tv_dac;
  1075. }
  1076. static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
  1077. radeon_device
  1078. *rdev)
  1079. {
  1080. struct radeon_encoder_lvds *lvds = NULL;
  1081. uint32_t fp_vert_stretch, fp_horz_stretch;
  1082. uint32_t ppll_div_sel, ppll_val;
  1083. uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
  1084. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1085. if (!lvds)
  1086. return NULL;
  1087. fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
  1088. fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
  1089. /* These should be fail-safe defaults, fingers crossed */
  1090. lvds->panel_pwr_delay = 200;
  1091. lvds->panel_vcc_delay = 2000;
  1092. lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  1093. lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
  1094. lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
  1095. if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
  1096. lvds->native_mode.vdisplay =
  1097. ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
  1098. RADEON_VERT_PANEL_SHIFT) + 1;
  1099. else
  1100. lvds->native_mode.vdisplay =
  1101. (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
  1102. if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
  1103. lvds->native_mode.hdisplay =
  1104. (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
  1105. RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
  1106. else
  1107. lvds->native_mode.hdisplay =
  1108. ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
  1109. if ((lvds->native_mode.hdisplay < 640) ||
  1110. (lvds->native_mode.vdisplay < 480)) {
  1111. lvds->native_mode.hdisplay = 640;
  1112. lvds->native_mode.vdisplay = 480;
  1113. }
  1114. ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
  1115. ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
  1116. if ((ppll_val & 0x000707ff) == 0x1bb)
  1117. lvds->use_bios_dividers = false;
  1118. else {
  1119. lvds->panel_ref_divider =
  1120. RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  1121. lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
  1122. lvds->panel_fb_divider = ppll_val & 0x7ff;
  1123. if ((lvds->panel_ref_divider != 0) &&
  1124. (lvds->panel_fb_divider > 3))
  1125. lvds->use_bios_dividers = true;
  1126. }
  1127. lvds->panel_vcc_delay = 200;
  1128. DRM_INFO("Panel info derived from registers\n");
  1129. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1130. lvds->native_mode.vdisplay);
  1131. return lvds;
  1132. }
  1133. struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
  1134. *encoder)
  1135. {
  1136. struct drm_device *dev = encoder->base.dev;
  1137. struct radeon_device *rdev = dev->dev_private;
  1138. uint16_t lcd_info;
  1139. uint32_t panel_setup;
  1140. char stmp[30];
  1141. int tmp, i;
  1142. struct radeon_encoder_lvds *lvds = NULL;
  1143. lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  1144. if (lcd_info) {
  1145. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1146. if (!lvds)
  1147. return NULL;
  1148. for (i = 0; i < 24; i++)
  1149. stmp[i] = RBIOS8(lcd_info + i + 1);
  1150. stmp[24] = 0;
  1151. DRM_INFO("Panel ID String: %s\n", stmp);
  1152. lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
  1153. lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
  1154. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1155. lvds->native_mode.vdisplay);
  1156. lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
  1157. lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
  1158. lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
  1159. lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
  1160. lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
  1161. lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
  1162. lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
  1163. lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
  1164. if ((lvds->panel_ref_divider != 0) &&
  1165. (lvds->panel_fb_divider > 3))
  1166. lvds->use_bios_dividers = true;
  1167. panel_setup = RBIOS32(lcd_info + 0x39);
  1168. lvds->lvds_gen_cntl = 0xff00;
  1169. if (panel_setup & 0x1)
  1170. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
  1171. if ((panel_setup >> 4) & 0x1)
  1172. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
  1173. switch ((panel_setup >> 8) & 0x7) {
  1174. case 0:
  1175. lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
  1176. break;
  1177. case 1:
  1178. lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
  1179. break;
  1180. case 2:
  1181. lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
  1182. break;
  1183. default:
  1184. break;
  1185. }
  1186. if ((panel_setup >> 16) & 0x1)
  1187. lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
  1188. if ((panel_setup >> 17) & 0x1)
  1189. lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
  1190. if ((panel_setup >> 18) & 0x1)
  1191. lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
  1192. if ((panel_setup >> 23) & 0x1)
  1193. lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
  1194. lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
  1195. for (i = 0; i < 32; i++) {
  1196. tmp = RBIOS16(lcd_info + 64 + i * 2);
  1197. if (tmp == 0)
  1198. break;
  1199. if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
  1200. (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
  1201. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1202. (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
  1203. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1204. (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
  1205. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1206. (RBIOS8(tmp + 23) * 8);
  1207. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1208. (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
  1209. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1210. ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
  1211. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1212. ((RBIOS16(tmp + 28) & 0xf800) >> 11);
  1213. lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
  1214. lvds->native_mode.flags = 0;
  1215. /* set crtc values */
  1216. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1217. }
  1218. }
  1219. } else {
  1220. DRM_INFO("No panel info found in BIOS\n");
  1221. lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
  1222. }
  1223. if (lvds)
  1224. encoder->native_mode = lvds->native_mode;
  1225. return lvds;
  1226. }
  1227. static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
  1228. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
  1229. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
  1230. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
  1231. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
  1232. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
  1233. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
  1234. {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
  1235. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
  1236. {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
  1237. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
  1238. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
  1239. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
  1240. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
  1241. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
  1242. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
  1243. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
  1244. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
  1245. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
  1246. };
  1247. bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
  1248. struct radeon_encoder_int_tmds *tmds)
  1249. {
  1250. struct drm_device *dev = encoder->base.dev;
  1251. struct radeon_device *rdev = dev->dev_private;
  1252. int i;
  1253. for (i = 0; i < 4; i++) {
  1254. tmds->tmds_pll[i].value =
  1255. default_tmds_pll[rdev->family][i].value;
  1256. tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
  1257. }
  1258. return true;
  1259. }
  1260. bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
  1261. struct radeon_encoder_int_tmds *tmds)
  1262. {
  1263. struct drm_device *dev = encoder->base.dev;
  1264. struct radeon_device *rdev = dev->dev_private;
  1265. uint16_t tmds_info;
  1266. int i, n;
  1267. uint8_t ver;
  1268. tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  1269. if (tmds_info) {
  1270. ver = RBIOS8(tmds_info);
  1271. DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
  1272. if (ver == 3) {
  1273. n = RBIOS8(tmds_info + 5) + 1;
  1274. if (n > 4)
  1275. n = 4;
  1276. for (i = 0; i < n; i++) {
  1277. tmds->tmds_pll[i].value =
  1278. RBIOS32(tmds_info + i * 10 + 0x08);
  1279. tmds->tmds_pll[i].freq =
  1280. RBIOS16(tmds_info + i * 10 + 0x10);
  1281. DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
  1282. tmds->tmds_pll[i].freq,
  1283. tmds->tmds_pll[i].value);
  1284. }
  1285. } else if (ver == 4) {
  1286. int stride = 0;
  1287. n = RBIOS8(tmds_info + 5) + 1;
  1288. if (n > 4)
  1289. n = 4;
  1290. for (i = 0; i < n; i++) {
  1291. tmds->tmds_pll[i].value =
  1292. RBIOS32(tmds_info + stride + 0x08);
  1293. tmds->tmds_pll[i].freq =
  1294. RBIOS16(tmds_info + stride + 0x10);
  1295. if (i == 0)
  1296. stride += 10;
  1297. else
  1298. stride += 6;
  1299. DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
  1300. tmds->tmds_pll[i].freq,
  1301. tmds->tmds_pll[i].value);
  1302. }
  1303. }
  1304. } else {
  1305. DRM_INFO("No TMDS info found in BIOS\n");
  1306. return false;
  1307. }
  1308. return true;
  1309. }
  1310. bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
  1311. struct radeon_encoder_ext_tmds *tmds)
  1312. {
  1313. struct drm_device *dev = encoder->base.dev;
  1314. struct radeon_device *rdev = dev->dev_private;
  1315. struct radeon_i2c_bus_rec i2c_bus;
  1316. /* default for macs */
  1317. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1318. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1319. /* XXX some macs have duallink chips */
  1320. switch (rdev->mode_info.connector_table) {
  1321. case CT_POWERBOOK_EXTERNAL:
  1322. case CT_MINI_EXTERNAL:
  1323. default:
  1324. tmds->dvo_chip = DVO_SIL164;
  1325. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1326. break;
  1327. }
  1328. return true;
  1329. }
  1330. bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
  1331. struct radeon_encoder_ext_tmds *tmds)
  1332. {
  1333. struct drm_device *dev = encoder->base.dev;
  1334. struct radeon_device *rdev = dev->dev_private;
  1335. uint16_t offset;
  1336. uint8_t ver;
  1337. enum radeon_combios_ddc gpio;
  1338. struct radeon_i2c_bus_rec i2c_bus;
  1339. tmds->i2c_bus = NULL;
  1340. if (rdev->flags & RADEON_IS_IGP) {
  1341. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1342. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1343. tmds->dvo_chip = DVO_SIL164;
  1344. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1345. } else {
  1346. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  1347. if (offset) {
  1348. ver = RBIOS8(offset);
  1349. DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
  1350. tmds->slave_addr = RBIOS8(offset + 4 + 2);
  1351. tmds->slave_addr >>= 1; /* 7 bit addressing */
  1352. gpio = RBIOS8(offset + 4 + 3);
  1353. if (gpio == DDC_LCD) {
  1354. /* MM i2c */
  1355. i2c_bus.valid = true;
  1356. i2c_bus.hw_capable = true;
  1357. i2c_bus.mm_i2c = true;
  1358. i2c_bus.i2c_id = 0xa0;
  1359. } else
  1360. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  1361. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1362. }
  1363. }
  1364. if (!tmds->i2c_bus) {
  1365. DRM_INFO("No valid Ext TMDS info found in BIOS\n");
  1366. return false;
  1367. }
  1368. return true;
  1369. }
  1370. bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
  1371. {
  1372. struct radeon_device *rdev = dev->dev_private;
  1373. struct radeon_i2c_bus_rec ddc_i2c;
  1374. struct radeon_hpd hpd;
  1375. rdev->mode_info.connector_table = radeon_connector_table;
  1376. if (rdev->mode_info.connector_table == CT_NONE) {
  1377. #ifdef CONFIG_PPC_PMAC
  1378. if (of_machine_is_compatible("PowerBook3,3")) {
  1379. /* powerbook with VGA */
  1380. rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
  1381. } else if (of_machine_is_compatible("PowerBook3,4") ||
  1382. of_machine_is_compatible("PowerBook3,5")) {
  1383. /* powerbook with internal tmds */
  1384. rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
  1385. } else if (of_machine_is_compatible("PowerBook5,1") ||
  1386. of_machine_is_compatible("PowerBook5,2") ||
  1387. of_machine_is_compatible("PowerBook5,3") ||
  1388. of_machine_is_compatible("PowerBook5,4") ||
  1389. of_machine_is_compatible("PowerBook5,5")) {
  1390. /* powerbook with external single link tmds (sil164) */
  1391. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1392. } else if (of_machine_is_compatible("PowerBook5,6")) {
  1393. /* powerbook with external dual or single link tmds */
  1394. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1395. } else if (of_machine_is_compatible("PowerBook5,7") ||
  1396. of_machine_is_compatible("PowerBook5,8") ||
  1397. of_machine_is_compatible("PowerBook5,9")) {
  1398. /* PowerBook6,2 ? */
  1399. /* powerbook with external dual link tmds (sil1178?) */
  1400. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1401. } else if (of_machine_is_compatible("PowerBook4,1") ||
  1402. of_machine_is_compatible("PowerBook4,2") ||
  1403. of_machine_is_compatible("PowerBook4,3") ||
  1404. of_machine_is_compatible("PowerBook6,3") ||
  1405. of_machine_is_compatible("PowerBook6,5") ||
  1406. of_machine_is_compatible("PowerBook6,7")) {
  1407. /* ibook */
  1408. rdev->mode_info.connector_table = CT_IBOOK;
  1409. } else if (of_machine_is_compatible("PowerMac4,4")) {
  1410. /* emac */
  1411. rdev->mode_info.connector_table = CT_EMAC;
  1412. } else if (of_machine_is_compatible("PowerMac10,1")) {
  1413. /* mini with internal tmds */
  1414. rdev->mode_info.connector_table = CT_MINI_INTERNAL;
  1415. } else if (of_machine_is_compatible("PowerMac10,2")) {
  1416. /* mini with external tmds */
  1417. rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
  1418. } else if (of_machine_is_compatible("PowerMac12,1")) {
  1419. /* PowerMac8,1 ? */
  1420. /* imac g5 isight */
  1421. rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
  1422. } else if ((rdev->pdev->device == 0x4a48) &&
  1423. (rdev->pdev->subsystem_vendor == 0x1002) &&
  1424. (rdev->pdev->subsystem_device == 0x4a48)) {
  1425. /* Mac X800 */
  1426. rdev->mode_info.connector_table = CT_MAC_X800;
  1427. } else if ((of_machine_is_compatible("PowerMac7,2") ||
  1428. of_machine_is_compatible("PowerMac7,3")) &&
  1429. (rdev->pdev->device == 0x4150) &&
  1430. (rdev->pdev->subsystem_vendor == 0x1002) &&
  1431. (rdev->pdev->subsystem_device == 0x4150)) {
  1432. /* Mac G5 tower 9600 */
  1433. rdev->mode_info.connector_table = CT_MAC_G5_9600;
  1434. } else
  1435. #endif /* CONFIG_PPC_PMAC */
  1436. #ifdef CONFIG_PPC64
  1437. if (ASIC_IS_RN50(rdev))
  1438. rdev->mode_info.connector_table = CT_RN50_POWER;
  1439. else
  1440. #endif
  1441. rdev->mode_info.connector_table = CT_GENERIC;
  1442. }
  1443. switch (rdev->mode_info.connector_table) {
  1444. case CT_GENERIC:
  1445. DRM_INFO("Connector Table: %d (generic)\n",
  1446. rdev->mode_info.connector_table);
  1447. /* these are the most common settings */
  1448. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1449. /* VGA - primary dac */
  1450. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1451. hpd.hpd = RADEON_HPD_NONE;
  1452. radeon_add_legacy_encoder(dev,
  1453. radeon_get_encoder_enum(dev,
  1454. ATOM_DEVICE_CRT1_SUPPORT,
  1455. 1),
  1456. ATOM_DEVICE_CRT1_SUPPORT);
  1457. radeon_add_legacy_connector(dev, 0,
  1458. ATOM_DEVICE_CRT1_SUPPORT,
  1459. DRM_MODE_CONNECTOR_VGA,
  1460. &ddc_i2c,
  1461. CONNECTOR_OBJECT_ID_VGA,
  1462. &hpd);
  1463. } else if (rdev->flags & RADEON_IS_MOBILITY) {
  1464. /* LVDS */
  1465. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
  1466. hpd.hpd = RADEON_HPD_NONE;
  1467. radeon_add_legacy_encoder(dev,
  1468. radeon_get_encoder_enum(dev,
  1469. ATOM_DEVICE_LCD1_SUPPORT,
  1470. 0),
  1471. ATOM_DEVICE_LCD1_SUPPORT);
  1472. radeon_add_legacy_connector(dev, 0,
  1473. ATOM_DEVICE_LCD1_SUPPORT,
  1474. DRM_MODE_CONNECTOR_LVDS,
  1475. &ddc_i2c,
  1476. CONNECTOR_OBJECT_ID_LVDS,
  1477. &hpd);
  1478. /* VGA - primary dac */
  1479. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1480. hpd.hpd = RADEON_HPD_NONE;
  1481. radeon_add_legacy_encoder(dev,
  1482. radeon_get_encoder_enum(dev,
  1483. ATOM_DEVICE_CRT1_SUPPORT,
  1484. 1),
  1485. ATOM_DEVICE_CRT1_SUPPORT);
  1486. radeon_add_legacy_connector(dev, 1,
  1487. ATOM_DEVICE_CRT1_SUPPORT,
  1488. DRM_MODE_CONNECTOR_VGA,
  1489. &ddc_i2c,
  1490. CONNECTOR_OBJECT_ID_VGA,
  1491. &hpd);
  1492. } else {
  1493. /* DVI-I - tv dac, int tmds */
  1494. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1495. hpd.hpd = RADEON_HPD_1;
  1496. radeon_add_legacy_encoder(dev,
  1497. radeon_get_encoder_enum(dev,
  1498. ATOM_DEVICE_DFP1_SUPPORT,
  1499. 0),
  1500. ATOM_DEVICE_DFP1_SUPPORT);
  1501. radeon_add_legacy_encoder(dev,
  1502. radeon_get_encoder_enum(dev,
  1503. ATOM_DEVICE_CRT2_SUPPORT,
  1504. 2),
  1505. ATOM_DEVICE_CRT2_SUPPORT);
  1506. radeon_add_legacy_connector(dev, 0,
  1507. ATOM_DEVICE_DFP1_SUPPORT |
  1508. ATOM_DEVICE_CRT2_SUPPORT,
  1509. DRM_MODE_CONNECTOR_DVII,
  1510. &ddc_i2c,
  1511. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1512. &hpd);
  1513. /* VGA - primary dac */
  1514. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1515. hpd.hpd = RADEON_HPD_NONE;
  1516. radeon_add_legacy_encoder(dev,
  1517. radeon_get_encoder_enum(dev,
  1518. ATOM_DEVICE_CRT1_SUPPORT,
  1519. 1),
  1520. ATOM_DEVICE_CRT1_SUPPORT);
  1521. radeon_add_legacy_connector(dev, 1,
  1522. ATOM_DEVICE_CRT1_SUPPORT,
  1523. DRM_MODE_CONNECTOR_VGA,
  1524. &ddc_i2c,
  1525. CONNECTOR_OBJECT_ID_VGA,
  1526. &hpd);
  1527. }
  1528. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1529. /* TV - tv dac */
  1530. ddc_i2c.valid = false;
  1531. hpd.hpd = RADEON_HPD_NONE;
  1532. radeon_add_legacy_encoder(dev,
  1533. radeon_get_encoder_enum(dev,
  1534. ATOM_DEVICE_TV1_SUPPORT,
  1535. 2),
  1536. ATOM_DEVICE_TV1_SUPPORT);
  1537. radeon_add_legacy_connector(dev, 2,
  1538. ATOM_DEVICE_TV1_SUPPORT,
  1539. DRM_MODE_CONNECTOR_SVIDEO,
  1540. &ddc_i2c,
  1541. CONNECTOR_OBJECT_ID_SVIDEO,
  1542. &hpd);
  1543. }
  1544. break;
  1545. case CT_IBOOK:
  1546. DRM_INFO("Connector Table: %d (ibook)\n",
  1547. rdev->mode_info.connector_table);
  1548. /* LVDS */
  1549. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1550. hpd.hpd = RADEON_HPD_NONE;
  1551. radeon_add_legacy_encoder(dev,
  1552. radeon_get_encoder_enum(dev,
  1553. ATOM_DEVICE_LCD1_SUPPORT,
  1554. 0),
  1555. ATOM_DEVICE_LCD1_SUPPORT);
  1556. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1557. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1558. CONNECTOR_OBJECT_ID_LVDS,
  1559. &hpd);
  1560. /* VGA - TV DAC */
  1561. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1562. hpd.hpd = RADEON_HPD_NONE;
  1563. radeon_add_legacy_encoder(dev,
  1564. radeon_get_encoder_enum(dev,
  1565. ATOM_DEVICE_CRT2_SUPPORT,
  1566. 2),
  1567. ATOM_DEVICE_CRT2_SUPPORT);
  1568. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1569. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1570. CONNECTOR_OBJECT_ID_VGA,
  1571. &hpd);
  1572. /* TV - TV DAC */
  1573. ddc_i2c.valid = false;
  1574. hpd.hpd = RADEON_HPD_NONE;
  1575. radeon_add_legacy_encoder(dev,
  1576. radeon_get_encoder_enum(dev,
  1577. ATOM_DEVICE_TV1_SUPPORT,
  1578. 2),
  1579. ATOM_DEVICE_TV1_SUPPORT);
  1580. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1581. DRM_MODE_CONNECTOR_SVIDEO,
  1582. &ddc_i2c,
  1583. CONNECTOR_OBJECT_ID_SVIDEO,
  1584. &hpd);
  1585. break;
  1586. case CT_POWERBOOK_EXTERNAL:
  1587. DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
  1588. rdev->mode_info.connector_table);
  1589. /* LVDS */
  1590. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1591. hpd.hpd = RADEON_HPD_NONE;
  1592. radeon_add_legacy_encoder(dev,
  1593. radeon_get_encoder_enum(dev,
  1594. ATOM_DEVICE_LCD1_SUPPORT,
  1595. 0),
  1596. ATOM_DEVICE_LCD1_SUPPORT);
  1597. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1598. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1599. CONNECTOR_OBJECT_ID_LVDS,
  1600. &hpd);
  1601. /* DVI-I - primary dac, ext tmds */
  1602. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1603. hpd.hpd = RADEON_HPD_2; /* ??? */
  1604. radeon_add_legacy_encoder(dev,
  1605. radeon_get_encoder_enum(dev,
  1606. ATOM_DEVICE_DFP2_SUPPORT,
  1607. 0),
  1608. ATOM_DEVICE_DFP2_SUPPORT);
  1609. radeon_add_legacy_encoder(dev,
  1610. radeon_get_encoder_enum(dev,
  1611. ATOM_DEVICE_CRT1_SUPPORT,
  1612. 1),
  1613. ATOM_DEVICE_CRT1_SUPPORT);
  1614. /* XXX some are SL */
  1615. radeon_add_legacy_connector(dev, 1,
  1616. ATOM_DEVICE_DFP2_SUPPORT |
  1617. ATOM_DEVICE_CRT1_SUPPORT,
  1618. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1619. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1620. &hpd);
  1621. /* TV - TV DAC */
  1622. ddc_i2c.valid = false;
  1623. hpd.hpd = RADEON_HPD_NONE;
  1624. radeon_add_legacy_encoder(dev,
  1625. radeon_get_encoder_enum(dev,
  1626. ATOM_DEVICE_TV1_SUPPORT,
  1627. 2),
  1628. ATOM_DEVICE_TV1_SUPPORT);
  1629. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1630. DRM_MODE_CONNECTOR_SVIDEO,
  1631. &ddc_i2c,
  1632. CONNECTOR_OBJECT_ID_SVIDEO,
  1633. &hpd);
  1634. break;
  1635. case CT_POWERBOOK_INTERNAL:
  1636. DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
  1637. rdev->mode_info.connector_table);
  1638. /* LVDS */
  1639. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1640. hpd.hpd = RADEON_HPD_NONE;
  1641. radeon_add_legacy_encoder(dev,
  1642. radeon_get_encoder_enum(dev,
  1643. ATOM_DEVICE_LCD1_SUPPORT,
  1644. 0),
  1645. ATOM_DEVICE_LCD1_SUPPORT);
  1646. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1647. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1648. CONNECTOR_OBJECT_ID_LVDS,
  1649. &hpd);
  1650. /* DVI-I - primary dac, int tmds */
  1651. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1652. hpd.hpd = RADEON_HPD_1; /* ??? */
  1653. radeon_add_legacy_encoder(dev,
  1654. radeon_get_encoder_enum(dev,
  1655. ATOM_DEVICE_DFP1_SUPPORT,
  1656. 0),
  1657. ATOM_DEVICE_DFP1_SUPPORT);
  1658. radeon_add_legacy_encoder(dev,
  1659. radeon_get_encoder_enum(dev,
  1660. ATOM_DEVICE_CRT1_SUPPORT,
  1661. 1),
  1662. ATOM_DEVICE_CRT1_SUPPORT);
  1663. radeon_add_legacy_connector(dev, 1,
  1664. ATOM_DEVICE_DFP1_SUPPORT |
  1665. ATOM_DEVICE_CRT1_SUPPORT,
  1666. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1667. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1668. &hpd);
  1669. /* TV - TV DAC */
  1670. ddc_i2c.valid = false;
  1671. hpd.hpd = RADEON_HPD_NONE;
  1672. radeon_add_legacy_encoder(dev,
  1673. radeon_get_encoder_enum(dev,
  1674. ATOM_DEVICE_TV1_SUPPORT,
  1675. 2),
  1676. ATOM_DEVICE_TV1_SUPPORT);
  1677. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1678. DRM_MODE_CONNECTOR_SVIDEO,
  1679. &ddc_i2c,
  1680. CONNECTOR_OBJECT_ID_SVIDEO,
  1681. &hpd);
  1682. break;
  1683. case CT_POWERBOOK_VGA:
  1684. DRM_INFO("Connector Table: %d (powerbook vga)\n",
  1685. rdev->mode_info.connector_table);
  1686. /* LVDS */
  1687. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1688. hpd.hpd = RADEON_HPD_NONE;
  1689. radeon_add_legacy_encoder(dev,
  1690. radeon_get_encoder_enum(dev,
  1691. ATOM_DEVICE_LCD1_SUPPORT,
  1692. 0),
  1693. ATOM_DEVICE_LCD1_SUPPORT);
  1694. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1695. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1696. CONNECTOR_OBJECT_ID_LVDS,
  1697. &hpd);
  1698. /* VGA - primary dac */
  1699. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1700. hpd.hpd = RADEON_HPD_NONE;
  1701. radeon_add_legacy_encoder(dev,
  1702. radeon_get_encoder_enum(dev,
  1703. ATOM_DEVICE_CRT1_SUPPORT,
  1704. 1),
  1705. ATOM_DEVICE_CRT1_SUPPORT);
  1706. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
  1707. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1708. CONNECTOR_OBJECT_ID_VGA,
  1709. &hpd);
  1710. /* TV - TV DAC */
  1711. ddc_i2c.valid = false;
  1712. hpd.hpd = RADEON_HPD_NONE;
  1713. radeon_add_legacy_encoder(dev,
  1714. radeon_get_encoder_enum(dev,
  1715. ATOM_DEVICE_TV1_SUPPORT,
  1716. 2),
  1717. ATOM_DEVICE_TV1_SUPPORT);
  1718. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1719. DRM_MODE_CONNECTOR_SVIDEO,
  1720. &ddc_i2c,
  1721. CONNECTOR_OBJECT_ID_SVIDEO,
  1722. &hpd);
  1723. break;
  1724. case CT_MINI_EXTERNAL:
  1725. DRM_INFO("Connector Table: %d (mini external tmds)\n",
  1726. rdev->mode_info.connector_table);
  1727. /* DVI-I - tv dac, ext tmds */
  1728. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1729. hpd.hpd = RADEON_HPD_2; /* ??? */
  1730. radeon_add_legacy_encoder(dev,
  1731. radeon_get_encoder_enum(dev,
  1732. ATOM_DEVICE_DFP2_SUPPORT,
  1733. 0),
  1734. ATOM_DEVICE_DFP2_SUPPORT);
  1735. radeon_add_legacy_encoder(dev,
  1736. radeon_get_encoder_enum(dev,
  1737. ATOM_DEVICE_CRT2_SUPPORT,
  1738. 2),
  1739. ATOM_DEVICE_CRT2_SUPPORT);
  1740. /* XXX are any DL? */
  1741. radeon_add_legacy_connector(dev, 0,
  1742. ATOM_DEVICE_DFP2_SUPPORT |
  1743. ATOM_DEVICE_CRT2_SUPPORT,
  1744. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1745. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1746. &hpd);
  1747. /* TV - TV DAC */
  1748. ddc_i2c.valid = false;
  1749. hpd.hpd = RADEON_HPD_NONE;
  1750. radeon_add_legacy_encoder(dev,
  1751. radeon_get_encoder_enum(dev,
  1752. ATOM_DEVICE_TV1_SUPPORT,
  1753. 2),
  1754. ATOM_DEVICE_TV1_SUPPORT);
  1755. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1756. DRM_MODE_CONNECTOR_SVIDEO,
  1757. &ddc_i2c,
  1758. CONNECTOR_OBJECT_ID_SVIDEO,
  1759. &hpd);
  1760. break;
  1761. case CT_MINI_INTERNAL:
  1762. DRM_INFO("Connector Table: %d (mini internal tmds)\n",
  1763. rdev->mode_info.connector_table);
  1764. /* DVI-I - tv dac, int tmds */
  1765. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1766. hpd.hpd = RADEON_HPD_1; /* ??? */
  1767. radeon_add_legacy_encoder(dev,
  1768. radeon_get_encoder_enum(dev,
  1769. ATOM_DEVICE_DFP1_SUPPORT,
  1770. 0),
  1771. ATOM_DEVICE_DFP1_SUPPORT);
  1772. radeon_add_legacy_encoder(dev,
  1773. radeon_get_encoder_enum(dev,
  1774. ATOM_DEVICE_CRT2_SUPPORT,
  1775. 2),
  1776. ATOM_DEVICE_CRT2_SUPPORT);
  1777. radeon_add_legacy_connector(dev, 0,
  1778. ATOM_DEVICE_DFP1_SUPPORT |
  1779. ATOM_DEVICE_CRT2_SUPPORT,
  1780. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1781. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1782. &hpd);
  1783. /* TV - TV DAC */
  1784. ddc_i2c.valid = false;
  1785. hpd.hpd = RADEON_HPD_NONE;
  1786. radeon_add_legacy_encoder(dev,
  1787. radeon_get_encoder_enum(dev,
  1788. ATOM_DEVICE_TV1_SUPPORT,
  1789. 2),
  1790. ATOM_DEVICE_TV1_SUPPORT);
  1791. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1792. DRM_MODE_CONNECTOR_SVIDEO,
  1793. &ddc_i2c,
  1794. CONNECTOR_OBJECT_ID_SVIDEO,
  1795. &hpd);
  1796. break;
  1797. case CT_IMAC_G5_ISIGHT:
  1798. DRM_INFO("Connector Table: %d (imac g5 isight)\n",
  1799. rdev->mode_info.connector_table);
  1800. /* DVI-D - int tmds */
  1801. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1802. hpd.hpd = RADEON_HPD_1; /* ??? */
  1803. radeon_add_legacy_encoder(dev,
  1804. radeon_get_encoder_enum(dev,
  1805. ATOM_DEVICE_DFP1_SUPPORT,
  1806. 0),
  1807. ATOM_DEVICE_DFP1_SUPPORT);
  1808. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
  1809. DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
  1810. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  1811. &hpd);
  1812. /* VGA - tv dac */
  1813. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1814. hpd.hpd = RADEON_HPD_NONE;
  1815. radeon_add_legacy_encoder(dev,
  1816. radeon_get_encoder_enum(dev,
  1817. ATOM_DEVICE_CRT2_SUPPORT,
  1818. 2),
  1819. ATOM_DEVICE_CRT2_SUPPORT);
  1820. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1821. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1822. CONNECTOR_OBJECT_ID_VGA,
  1823. &hpd);
  1824. /* TV - TV DAC */
  1825. ddc_i2c.valid = false;
  1826. hpd.hpd = RADEON_HPD_NONE;
  1827. radeon_add_legacy_encoder(dev,
  1828. radeon_get_encoder_enum(dev,
  1829. ATOM_DEVICE_TV1_SUPPORT,
  1830. 2),
  1831. ATOM_DEVICE_TV1_SUPPORT);
  1832. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1833. DRM_MODE_CONNECTOR_SVIDEO,
  1834. &ddc_i2c,
  1835. CONNECTOR_OBJECT_ID_SVIDEO,
  1836. &hpd);
  1837. break;
  1838. case CT_EMAC:
  1839. DRM_INFO("Connector Table: %d (emac)\n",
  1840. rdev->mode_info.connector_table);
  1841. /* VGA - primary dac */
  1842. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1843. hpd.hpd = RADEON_HPD_NONE;
  1844. radeon_add_legacy_encoder(dev,
  1845. radeon_get_encoder_enum(dev,
  1846. ATOM_DEVICE_CRT1_SUPPORT,
  1847. 1),
  1848. ATOM_DEVICE_CRT1_SUPPORT);
  1849. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1850. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1851. CONNECTOR_OBJECT_ID_VGA,
  1852. &hpd);
  1853. /* VGA - tv dac */
  1854. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1855. hpd.hpd = RADEON_HPD_NONE;
  1856. radeon_add_legacy_encoder(dev,
  1857. radeon_get_encoder_enum(dev,
  1858. ATOM_DEVICE_CRT2_SUPPORT,
  1859. 2),
  1860. ATOM_DEVICE_CRT2_SUPPORT);
  1861. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1862. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1863. CONNECTOR_OBJECT_ID_VGA,
  1864. &hpd);
  1865. /* TV - TV DAC */
  1866. ddc_i2c.valid = false;
  1867. hpd.hpd = RADEON_HPD_NONE;
  1868. radeon_add_legacy_encoder(dev,
  1869. radeon_get_encoder_enum(dev,
  1870. ATOM_DEVICE_TV1_SUPPORT,
  1871. 2),
  1872. ATOM_DEVICE_TV1_SUPPORT);
  1873. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1874. DRM_MODE_CONNECTOR_SVIDEO,
  1875. &ddc_i2c,
  1876. CONNECTOR_OBJECT_ID_SVIDEO,
  1877. &hpd);
  1878. break;
  1879. case CT_RN50_POWER:
  1880. DRM_INFO("Connector Table: %d (rn50-power)\n",
  1881. rdev->mode_info.connector_table);
  1882. /* VGA - primary dac */
  1883. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1884. hpd.hpd = RADEON_HPD_NONE;
  1885. radeon_add_legacy_encoder(dev,
  1886. radeon_get_encoder_enum(dev,
  1887. ATOM_DEVICE_CRT1_SUPPORT,
  1888. 1),
  1889. ATOM_DEVICE_CRT1_SUPPORT);
  1890. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1891. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1892. CONNECTOR_OBJECT_ID_VGA,
  1893. &hpd);
  1894. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1895. hpd.hpd = RADEON_HPD_NONE;
  1896. radeon_add_legacy_encoder(dev,
  1897. radeon_get_encoder_enum(dev,
  1898. ATOM_DEVICE_CRT2_SUPPORT,
  1899. 2),
  1900. ATOM_DEVICE_CRT2_SUPPORT);
  1901. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1902. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1903. CONNECTOR_OBJECT_ID_VGA,
  1904. &hpd);
  1905. break;
  1906. case CT_MAC_X800:
  1907. DRM_INFO("Connector Table: %d (mac x800)\n",
  1908. rdev->mode_info.connector_table);
  1909. /* DVI - primary dac, internal tmds */
  1910. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1911. hpd.hpd = RADEON_HPD_1; /* ??? */
  1912. radeon_add_legacy_encoder(dev,
  1913. radeon_get_encoder_enum(dev,
  1914. ATOM_DEVICE_DFP1_SUPPORT,
  1915. 0),
  1916. ATOM_DEVICE_DFP1_SUPPORT);
  1917. radeon_add_legacy_encoder(dev,
  1918. radeon_get_encoder_enum(dev,
  1919. ATOM_DEVICE_CRT1_SUPPORT,
  1920. 1),
  1921. ATOM_DEVICE_CRT1_SUPPORT);
  1922. radeon_add_legacy_connector(dev, 0,
  1923. ATOM_DEVICE_DFP1_SUPPORT |
  1924. ATOM_DEVICE_CRT1_SUPPORT,
  1925. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1926. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1927. &hpd);
  1928. /* DVI - tv dac, dvo */
  1929. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1930. hpd.hpd = RADEON_HPD_2; /* ??? */
  1931. radeon_add_legacy_encoder(dev,
  1932. radeon_get_encoder_enum(dev,
  1933. ATOM_DEVICE_DFP2_SUPPORT,
  1934. 0),
  1935. ATOM_DEVICE_DFP2_SUPPORT);
  1936. radeon_add_legacy_encoder(dev,
  1937. radeon_get_encoder_enum(dev,
  1938. ATOM_DEVICE_CRT2_SUPPORT,
  1939. 2),
  1940. ATOM_DEVICE_CRT2_SUPPORT);
  1941. radeon_add_legacy_connector(dev, 1,
  1942. ATOM_DEVICE_DFP2_SUPPORT |
  1943. ATOM_DEVICE_CRT2_SUPPORT,
  1944. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1945. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1946. &hpd);
  1947. break;
  1948. case CT_MAC_G5_9600:
  1949. DRM_INFO("Connector Table: %d (mac g5 9600)\n",
  1950. rdev->mode_info.connector_table);
  1951. /* DVI - tv dac, dvo */
  1952. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1953. hpd.hpd = RADEON_HPD_1; /* ??? */
  1954. radeon_add_legacy_encoder(dev,
  1955. radeon_get_encoder_enum(dev,
  1956. ATOM_DEVICE_DFP2_SUPPORT,
  1957. 0),
  1958. ATOM_DEVICE_DFP2_SUPPORT);
  1959. radeon_add_legacy_encoder(dev,
  1960. radeon_get_encoder_enum(dev,
  1961. ATOM_DEVICE_CRT2_SUPPORT,
  1962. 2),
  1963. ATOM_DEVICE_CRT2_SUPPORT);
  1964. radeon_add_legacy_connector(dev, 0,
  1965. ATOM_DEVICE_DFP2_SUPPORT |
  1966. ATOM_DEVICE_CRT2_SUPPORT,
  1967. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1968. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1969. &hpd);
  1970. /* ADC - primary dac, internal tmds */
  1971. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1972. hpd.hpd = RADEON_HPD_2; /* ??? */
  1973. radeon_add_legacy_encoder(dev,
  1974. radeon_get_encoder_enum(dev,
  1975. ATOM_DEVICE_DFP1_SUPPORT,
  1976. 0),
  1977. ATOM_DEVICE_DFP1_SUPPORT);
  1978. radeon_add_legacy_encoder(dev,
  1979. radeon_get_encoder_enum(dev,
  1980. ATOM_DEVICE_CRT1_SUPPORT,
  1981. 1),
  1982. ATOM_DEVICE_CRT1_SUPPORT);
  1983. radeon_add_legacy_connector(dev, 1,
  1984. ATOM_DEVICE_DFP1_SUPPORT |
  1985. ATOM_DEVICE_CRT1_SUPPORT,
  1986. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1987. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1988. &hpd);
  1989. /* TV - TV DAC */
  1990. ddc_i2c.valid = false;
  1991. hpd.hpd = RADEON_HPD_NONE;
  1992. radeon_add_legacy_encoder(dev,
  1993. radeon_get_encoder_enum(dev,
  1994. ATOM_DEVICE_TV1_SUPPORT,
  1995. 2),
  1996. ATOM_DEVICE_TV1_SUPPORT);
  1997. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1998. DRM_MODE_CONNECTOR_SVIDEO,
  1999. &ddc_i2c,
  2000. CONNECTOR_OBJECT_ID_SVIDEO,
  2001. &hpd);
  2002. break;
  2003. default:
  2004. DRM_INFO("Connector table: %d (invalid)\n",
  2005. rdev->mode_info.connector_table);
  2006. return false;
  2007. }
  2008. radeon_link_encoder_connector(dev);
  2009. return true;
  2010. }
  2011. static bool radeon_apply_legacy_quirks(struct drm_device *dev,
  2012. int bios_index,
  2013. enum radeon_combios_connector
  2014. *legacy_connector,
  2015. struct radeon_i2c_bus_rec *ddc_i2c,
  2016. struct radeon_hpd *hpd)
  2017. {
  2018. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  2019. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  2020. if (dev->pdev->device == 0x515e &&
  2021. dev->pdev->subsystem_vendor == 0x1014) {
  2022. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  2023. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  2024. return false;
  2025. }
  2026. /* X300 card with extra non-existent DVI port */
  2027. if (dev->pdev->device == 0x5B60 &&
  2028. dev->pdev->subsystem_vendor == 0x17af &&
  2029. dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  2030. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  2031. return false;
  2032. }
  2033. return true;
  2034. }
  2035. static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
  2036. {
  2037. /* Acer 5102 has non-existent TV port */
  2038. if (dev->pdev->device == 0x5975 &&
  2039. dev->pdev->subsystem_vendor == 0x1025 &&
  2040. dev->pdev->subsystem_device == 0x009f)
  2041. return false;
  2042. /* HP dc5750 has non-existent TV port */
  2043. if (dev->pdev->device == 0x5974 &&
  2044. dev->pdev->subsystem_vendor == 0x103c &&
  2045. dev->pdev->subsystem_device == 0x280a)
  2046. return false;
  2047. /* MSI S270 has non-existent TV port */
  2048. if (dev->pdev->device == 0x5955 &&
  2049. dev->pdev->subsystem_vendor == 0x1462 &&
  2050. dev->pdev->subsystem_device == 0x0131)
  2051. return false;
  2052. return true;
  2053. }
  2054. static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
  2055. {
  2056. struct radeon_device *rdev = dev->dev_private;
  2057. uint32_t ext_tmds_info;
  2058. if (rdev->flags & RADEON_IS_IGP) {
  2059. if (is_dvi_d)
  2060. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2061. else
  2062. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2063. }
  2064. ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2065. if (ext_tmds_info) {
  2066. uint8_t rev = RBIOS8(ext_tmds_info);
  2067. uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
  2068. if (rev >= 3) {
  2069. if (is_dvi_d)
  2070. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2071. else
  2072. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2073. } else {
  2074. if (flags & 1) {
  2075. if (is_dvi_d)
  2076. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2077. else
  2078. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2079. }
  2080. }
  2081. }
  2082. if (is_dvi_d)
  2083. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2084. else
  2085. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2086. }
  2087. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  2088. {
  2089. struct radeon_device *rdev = dev->dev_private;
  2090. uint32_t conn_info, entry, devices;
  2091. uint16_t tmp, connector_object_id;
  2092. enum radeon_combios_ddc ddc_type;
  2093. enum radeon_combios_connector connector;
  2094. int i = 0;
  2095. struct radeon_i2c_bus_rec ddc_i2c;
  2096. struct radeon_hpd hpd;
  2097. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  2098. if (conn_info) {
  2099. for (i = 0; i < 4; i++) {
  2100. entry = conn_info + 2 + i * 2;
  2101. if (!RBIOS16(entry))
  2102. break;
  2103. tmp = RBIOS16(entry);
  2104. connector = (tmp >> 12) & 0xf;
  2105. ddc_type = (tmp >> 8) & 0xf;
  2106. ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2107. switch (connector) {
  2108. case CONNECTOR_PROPRIETARY_LEGACY:
  2109. case CONNECTOR_DVI_I_LEGACY:
  2110. case CONNECTOR_DVI_D_LEGACY:
  2111. if ((tmp >> 4) & 0x1)
  2112. hpd.hpd = RADEON_HPD_2;
  2113. else
  2114. hpd.hpd = RADEON_HPD_1;
  2115. break;
  2116. default:
  2117. hpd.hpd = RADEON_HPD_NONE;
  2118. break;
  2119. }
  2120. if (!radeon_apply_legacy_quirks(dev, i, &connector,
  2121. &ddc_i2c, &hpd))
  2122. continue;
  2123. switch (connector) {
  2124. case CONNECTOR_PROPRIETARY_LEGACY:
  2125. if ((tmp >> 4) & 0x1)
  2126. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2127. else
  2128. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2129. radeon_add_legacy_encoder(dev,
  2130. radeon_get_encoder_enum
  2131. (dev, devices, 0),
  2132. devices);
  2133. radeon_add_legacy_connector(dev, i, devices,
  2134. legacy_connector_convert
  2135. [connector],
  2136. &ddc_i2c,
  2137. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  2138. &hpd);
  2139. break;
  2140. case CONNECTOR_CRT_LEGACY:
  2141. if (tmp & 0x1) {
  2142. devices = ATOM_DEVICE_CRT2_SUPPORT;
  2143. radeon_add_legacy_encoder(dev,
  2144. radeon_get_encoder_enum
  2145. (dev,
  2146. ATOM_DEVICE_CRT2_SUPPORT,
  2147. 2),
  2148. ATOM_DEVICE_CRT2_SUPPORT);
  2149. } else {
  2150. devices = ATOM_DEVICE_CRT1_SUPPORT;
  2151. radeon_add_legacy_encoder(dev,
  2152. radeon_get_encoder_enum
  2153. (dev,
  2154. ATOM_DEVICE_CRT1_SUPPORT,
  2155. 1),
  2156. ATOM_DEVICE_CRT1_SUPPORT);
  2157. }
  2158. radeon_add_legacy_connector(dev,
  2159. i,
  2160. devices,
  2161. legacy_connector_convert
  2162. [connector],
  2163. &ddc_i2c,
  2164. CONNECTOR_OBJECT_ID_VGA,
  2165. &hpd);
  2166. break;
  2167. case CONNECTOR_DVI_I_LEGACY:
  2168. devices = 0;
  2169. if (tmp & 0x1) {
  2170. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  2171. radeon_add_legacy_encoder(dev,
  2172. radeon_get_encoder_enum
  2173. (dev,
  2174. ATOM_DEVICE_CRT2_SUPPORT,
  2175. 2),
  2176. ATOM_DEVICE_CRT2_SUPPORT);
  2177. } else {
  2178. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  2179. radeon_add_legacy_encoder(dev,
  2180. radeon_get_encoder_enum
  2181. (dev,
  2182. ATOM_DEVICE_CRT1_SUPPORT,
  2183. 1),
  2184. ATOM_DEVICE_CRT1_SUPPORT);
  2185. }
  2186. if ((tmp >> 4) & 0x1) {
  2187. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  2188. radeon_add_legacy_encoder(dev,
  2189. radeon_get_encoder_enum
  2190. (dev,
  2191. ATOM_DEVICE_DFP2_SUPPORT,
  2192. 0),
  2193. ATOM_DEVICE_DFP2_SUPPORT);
  2194. connector_object_id = combios_check_dl_dvi(dev, 0);
  2195. } else {
  2196. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  2197. radeon_add_legacy_encoder(dev,
  2198. radeon_get_encoder_enum
  2199. (dev,
  2200. ATOM_DEVICE_DFP1_SUPPORT,
  2201. 0),
  2202. ATOM_DEVICE_DFP1_SUPPORT);
  2203. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2204. }
  2205. radeon_add_legacy_connector(dev,
  2206. i,
  2207. devices,
  2208. legacy_connector_convert
  2209. [connector],
  2210. &ddc_i2c,
  2211. connector_object_id,
  2212. &hpd);
  2213. break;
  2214. case CONNECTOR_DVI_D_LEGACY:
  2215. if ((tmp >> 4) & 0x1) {
  2216. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2217. connector_object_id = combios_check_dl_dvi(dev, 1);
  2218. } else {
  2219. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2220. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2221. }
  2222. radeon_add_legacy_encoder(dev,
  2223. radeon_get_encoder_enum
  2224. (dev, devices, 0),
  2225. devices);
  2226. radeon_add_legacy_connector(dev, i, devices,
  2227. legacy_connector_convert
  2228. [connector],
  2229. &ddc_i2c,
  2230. connector_object_id,
  2231. &hpd);
  2232. break;
  2233. case CONNECTOR_CTV_LEGACY:
  2234. case CONNECTOR_STV_LEGACY:
  2235. radeon_add_legacy_encoder(dev,
  2236. radeon_get_encoder_enum
  2237. (dev,
  2238. ATOM_DEVICE_TV1_SUPPORT,
  2239. 2),
  2240. ATOM_DEVICE_TV1_SUPPORT);
  2241. radeon_add_legacy_connector(dev, i,
  2242. ATOM_DEVICE_TV1_SUPPORT,
  2243. legacy_connector_convert
  2244. [connector],
  2245. &ddc_i2c,
  2246. CONNECTOR_OBJECT_ID_SVIDEO,
  2247. &hpd);
  2248. break;
  2249. default:
  2250. DRM_ERROR("Unknown connector type: %d\n",
  2251. connector);
  2252. continue;
  2253. }
  2254. }
  2255. } else {
  2256. uint16_t tmds_info =
  2257. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  2258. if (tmds_info) {
  2259. DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
  2260. radeon_add_legacy_encoder(dev,
  2261. radeon_get_encoder_enum(dev,
  2262. ATOM_DEVICE_CRT1_SUPPORT,
  2263. 1),
  2264. ATOM_DEVICE_CRT1_SUPPORT);
  2265. radeon_add_legacy_encoder(dev,
  2266. radeon_get_encoder_enum(dev,
  2267. ATOM_DEVICE_DFP1_SUPPORT,
  2268. 0),
  2269. ATOM_DEVICE_DFP1_SUPPORT);
  2270. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  2271. hpd.hpd = RADEON_HPD_1;
  2272. radeon_add_legacy_connector(dev,
  2273. 0,
  2274. ATOM_DEVICE_CRT1_SUPPORT |
  2275. ATOM_DEVICE_DFP1_SUPPORT,
  2276. DRM_MODE_CONNECTOR_DVII,
  2277. &ddc_i2c,
  2278. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2279. &hpd);
  2280. } else {
  2281. uint16_t crt_info =
  2282. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  2283. DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
  2284. if (crt_info) {
  2285. radeon_add_legacy_encoder(dev,
  2286. radeon_get_encoder_enum(dev,
  2287. ATOM_DEVICE_CRT1_SUPPORT,
  2288. 1),
  2289. ATOM_DEVICE_CRT1_SUPPORT);
  2290. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  2291. hpd.hpd = RADEON_HPD_NONE;
  2292. radeon_add_legacy_connector(dev,
  2293. 0,
  2294. ATOM_DEVICE_CRT1_SUPPORT,
  2295. DRM_MODE_CONNECTOR_VGA,
  2296. &ddc_i2c,
  2297. CONNECTOR_OBJECT_ID_VGA,
  2298. &hpd);
  2299. } else {
  2300. DRM_DEBUG_KMS("No connector info found\n");
  2301. return false;
  2302. }
  2303. }
  2304. }
  2305. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  2306. uint16_t lcd_info =
  2307. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  2308. if (lcd_info) {
  2309. uint16_t lcd_ddc_info =
  2310. combios_get_table_offset(dev,
  2311. COMBIOS_LCD_DDC_INFO_TABLE);
  2312. radeon_add_legacy_encoder(dev,
  2313. radeon_get_encoder_enum(dev,
  2314. ATOM_DEVICE_LCD1_SUPPORT,
  2315. 0),
  2316. ATOM_DEVICE_LCD1_SUPPORT);
  2317. if (lcd_ddc_info) {
  2318. ddc_type = RBIOS8(lcd_ddc_info + 2);
  2319. switch (ddc_type) {
  2320. case DDC_LCD:
  2321. ddc_i2c =
  2322. combios_setup_i2c_bus(rdev,
  2323. DDC_LCD,
  2324. RBIOS32(lcd_ddc_info + 3),
  2325. RBIOS32(lcd_ddc_info + 7));
  2326. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2327. break;
  2328. case DDC_GPIO:
  2329. ddc_i2c =
  2330. combios_setup_i2c_bus(rdev,
  2331. DDC_GPIO,
  2332. RBIOS32(lcd_ddc_info + 3),
  2333. RBIOS32(lcd_ddc_info + 7));
  2334. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2335. break;
  2336. default:
  2337. ddc_i2c =
  2338. combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2339. break;
  2340. }
  2341. DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
  2342. } else
  2343. ddc_i2c.valid = false;
  2344. hpd.hpd = RADEON_HPD_NONE;
  2345. radeon_add_legacy_connector(dev,
  2346. 5,
  2347. ATOM_DEVICE_LCD1_SUPPORT,
  2348. DRM_MODE_CONNECTOR_LVDS,
  2349. &ddc_i2c,
  2350. CONNECTOR_OBJECT_ID_LVDS,
  2351. &hpd);
  2352. }
  2353. }
  2354. /* check TV table */
  2355. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  2356. uint32_t tv_info =
  2357. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  2358. if (tv_info) {
  2359. if (RBIOS8(tv_info + 6) == 'T') {
  2360. if (radeon_apply_legacy_tv_quirks(dev)) {
  2361. hpd.hpd = RADEON_HPD_NONE;
  2362. ddc_i2c.valid = false;
  2363. radeon_add_legacy_encoder(dev,
  2364. radeon_get_encoder_enum
  2365. (dev,
  2366. ATOM_DEVICE_TV1_SUPPORT,
  2367. 2),
  2368. ATOM_DEVICE_TV1_SUPPORT);
  2369. radeon_add_legacy_connector(dev, 6,
  2370. ATOM_DEVICE_TV1_SUPPORT,
  2371. DRM_MODE_CONNECTOR_SVIDEO,
  2372. &ddc_i2c,
  2373. CONNECTOR_OBJECT_ID_SVIDEO,
  2374. &hpd);
  2375. }
  2376. }
  2377. }
  2378. }
  2379. radeon_link_encoder_connector(dev);
  2380. return true;
  2381. }
  2382. static const char *thermal_controller_names[] = {
  2383. "NONE",
  2384. "lm63",
  2385. "adm1032",
  2386. };
  2387. void radeon_combios_get_power_modes(struct radeon_device *rdev)
  2388. {
  2389. struct drm_device *dev = rdev->ddev;
  2390. u16 offset, misc, misc2 = 0;
  2391. u8 rev, blocks, tmp;
  2392. int state_index = 0;
  2393. rdev->pm.default_power_state_index = -1;
  2394. /* allocate 2 power states */
  2395. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
  2396. if (!rdev->pm.power_state) {
  2397. rdev->pm.default_power_state_index = state_index;
  2398. rdev->pm.num_power_states = 0;
  2399. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2400. rdev->pm.current_clock_mode_index = 0;
  2401. return;
  2402. }
  2403. /* check for a thermal chip */
  2404. offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
  2405. if (offset) {
  2406. u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
  2407. struct radeon_i2c_bus_rec i2c_bus;
  2408. rev = RBIOS8(offset);
  2409. if (rev == 0) {
  2410. thermal_controller = RBIOS8(offset + 3);
  2411. gpio = RBIOS8(offset + 4) & 0x3f;
  2412. i2c_addr = RBIOS8(offset + 5);
  2413. } else if (rev == 1) {
  2414. thermal_controller = RBIOS8(offset + 4);
  2415. gpio = RBIOS8(offset + 5) & 0x3f;
  2416. i2c_addr = RBIOS8(offset + 6);
  2417. } else if (rev == 2) {
  2418. thermal_controller = RBIOS8(offset + 4);
  2419. gpio = RBIOS8(offset + 5) & 0x3f;
  2420. i2c_addr = RBIOS8(offset + 6);
  2421. clk_bit = RBIOS8(offset + 0xa);
  2422. data_bit = RBIOS8(offset + 0xb);
  2423. }
  2424. if ((thermal_controller > 0) && (thermal_controller < 3)) {
  2425. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2426. thermal_controller_names[thermal_controller],
  2427. i2c_addr >> 1);
  2428. if (gpio == DDC_LCD) {
  2429. /* MM i2c */
  2430. i2c_bus.valid = true;
  2431. i2c_bus.hw_capable = true;
  2432. i2c_bus.mm_i2c = true;
  2433. i2c_bus.i2c_id = 0xa0;
  2434. } else if (gpio == DDC_GPIO)
  2435. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
  2436. else
  2437. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  2438. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2439. if (rdev->pm.i2c_bus) {
  2440. struct i2c_board_info info = { };
  2441. const char *name = thermal_controller_names[thermal_controller];
  2442. info.addr = i2c_addr >> 1;
  2443. strlcpy(info.type, name, sizeof(info.type));
  2444. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2445. }
  2446. }
  2447. }
  2448. if (rdev->flags & RADEON_IS_MOBILITY) {
  2449. offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
  2450. if (offset) {
  2451. rev = RBIOS8(offset);
  2452. blocks = RBIOS8(offset + 0x2);
  2453. /* power mode 0 tends to be the only valid one */
  2454. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2455. rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
  2456. rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
  2457. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  2458. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  2459. goto default_mode;
  2460. rdev->pm.power_state[state_index].type =
  2461. POWER_STATE_TYPE_BATTERY;
  2462. misc = RBIOS16(offset + 0x5 + 0x0);
  2463. if (rev > 4)
  2464. misc2 = RBIOS16(offset + 0x5 + 0xe);
  2465. rdev->pm.power_state[state_index].misc = misc;
  2466. rdev->pm.power_state[state_index].misc2 = misc2;
  2467. if (misc & 0x4) {
  2468. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
  2469. if (misc & 0x8)
  2470. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2471. true;
  2472. else
  2473. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2474. false;
  2475. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
  2476. if (rev < 6) {
  2477. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2478. RBIOS16(offset + 0x5 + 0xb) * 4;
  2479. tmp = RBIOS8(offset + 0x5 + 0xd);
  2480. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2481. } else {
  2482. u8 entries = RBIOS8(offset + 0x5 + 0xb);
  2483. u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
  2484. if (entries && voltage_table_offset) {
  2485. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2486. RBIOS16(voltage_table_offset) * 4;
  2487. tmp = RBIOS8(voltage_table_offset + 0x2);
  2488. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2489. } else
  2490. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
  2491. }
  2492. switch ((misc2 & 0x700) >> 8) {
  2493. case 0:
  2494. default:
  2495. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
  2496. break;
  2497. case 1:
  2498. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
  2499. break;
  2500. case 2:
  2501. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
  2502. break;
  2503. case 3:
  2504. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
  2505. break;
  2506. case 4:
  2507. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
  2508. break;
  2509. }
  2510. } else
  2511. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2512. if (rev > 6)
  2513. rdev->pm.power_state[state_index].pcie_lanes =
  2514. RBIOS8(offset + 0x5 + 0x10);
  2515. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2516. state_index++;
  2517. } else {
  2518. /* XXX figure out some good default low power mode for mobility cards w/out power tables */
  2519. }
  2520. } else {
  2521. /* XXX figure out some good default low power mode for desktop cards */
  2522. }
  2523. default_mode:
  2524. /* add the default mode */
  2525. rdev->pm.power_state[state_index].type =
  2526. POWER_STATE_TYPE_DEFAULT;
  2527. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2528. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2529. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2530. rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
  2531. if ((state_index > 0) &&
  2532. (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
  2533. rdev->pm.power_state[state_index].clock_info[0].voltage =
  2534. rdev->pm.power_state[0].clock_info[0].voltage;
  2535. else
  2536. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2537. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2538. rdev->pm.power_state[state_index].flags = 0;
  2539. rdev->pm.default_power_state_index = state_index;
  2540. rdev->pm.num_power_states = state_index + 1;
  2541. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2542. rdev->pm.current_clock_mode_index = 0;
  2543. }
  2544. void radeon_external_tmds_setup(struct drm_encoder *encoder)
  2545. {
  2546. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2547. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2548. if (!tmds)
  2549. return;
  2550. switch (tmds->dvo_chip) {
  2551. case DVO_SIL164:
  2552. /* sil 164 */
  2553. radeon_i2c_put_byte(tmds->i2c_bus,
  2554. tmds->slave_addr,
  2555. 0x08, 0x30);
  2556. radeon_i2c_put_byte(tmds->i2c_bus,
  2557. tmds->slave_addr,
  2558. 0x09, 0x00);
  2559. radeon_i2c_put_byte(tmds->i2c_bus,
  2560. tmds->slave_addr,
  2561. 0x0a, 0x90);
  2562. radeon_i2c_put_byte(tmds->i2c_bus,
  2563. tmds->slave_addr,
  2564. 0x0c, 0x89);
  2565. radeon_i2c_put_byte(tmds->i2c_bus,
  2566. tmds->slave_addr,
  2567. 0x08, 0x3b);
  2568. break;
  2569. case DVO_SIL1178:
  2570. /* sil 1178 - untested */
  2571. /*
  2572. * 0x0f, 0x44
  2573. * 0x0f, 0x4c
  2574. * 0x0e, 0x01
  2575. * 0x0a, 0x80
  2576. * 0x09, 0x30
  2577. * 0x0c, 0xc9
  2578. * 0x0d, 0x70
  2579. * 0x08, 0x32
  2580. * 0x08, 0x33
  2581. */
  2582. break;
  2583. default:
  2584. break;
  2585. }
  2586. }
  2587. bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
  2588. {
  2589. struct drm_device *dev = encoder->dev;
  2590. struct radeon_device *rdev = dev->dev_private;
  2591. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2592. uint16_t offset;
  2593. uint8_t blocks, slave_addr, rev;
  2594. uint32_t index, id;
  2595. uint32_t reg, val, and_mask, or_mask;
  2596. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2597. if (!tmds)
  2598. return false;
  2599. if (rdev->flags & RADEON_IS_IGP) {
  2600. offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
  2601. rev = RBIOS8(offset);
  2602. if (offset) {
  2603. rev = RBIOS8(offset);
  2604. if (rev > 1) {
  2605. blocks = RBIOS8(offset + 3);
  2606. index = offset + 4;
  2607. while (blocks > 0) {
  2608. id = RBIOS16(index);
  2609. index += 2;
  2610. switch (id >> 13) {
  2611. case 0:
  2612. reg = (id & 0x1fff) * 4;
  2613. val = RBIOS32(index);
  2614. index += 4;
  2615. WREG32(reg, val);
  2616. break;
  2617. case 2:
  2618. reg = (id & 0x1fff) * 4;
  2619. and_mask = RBIOS32(index);
  2620. index += 4;
  2621. or_mask = RBIOS32(index);
  2622. index += 4;
  2623. val = RREG32(reg);
  2624. val = (val & and_mask) | or_mask;
  2625. WREG32(reg, val);
  2626. break;
  2627. case 3:
  2628. val = RBIOS16(index);
  2629. index += 2;
  2630. udelay(val);
  2631. break;
  2632. case 4:
  2633. val = RBIOS16(index);
  2634. index += 2;
  2635. udelay(val * 1000);
  2636. break;
  2637. case 6:
  2638. slave_addr = id & 0xff;
  2639. slave_addr >>= 1; /* 7 bit addressing */
  2640. index++;
  2641. reg = RBIOS8(index);
  2642. index++;
  2643. val = RBIOS8(index);
  2644. index++;
  2645. radeon_i2c_put_byte(tmds->i2c_bus,
  2646. slave_addr,
  2647. reg, val);
  2648. break;
  2649. default:
  2650. DRM_ERROR("Unknown id %d\n", id >> 13);
  2651. break;
  2652. }
  2653. blocks--;
  2654. }
  2655. return true;
  2656. }
  2657. }
  2658. } else {
  2659. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2660. if (offset) {
  2661. index = offset + 10;
  2662. id = RBIOS16(index);
  2663. while (id != 0xffff) {
  2664. index += 2;
  2665. switch (id >> 13) {
  2666. case 0:
  2667. reg = (id & 0x1fff) * 4;
  2668. val = RBIOS32(index);
  2669. WREG32(reg, val);
  2670. break;
  2671. case 2:
  2672. reg = (id & 0x1fff) * 4;
  2673. and_mask = RBIOS32(index);
  2674. index += 4;
  2675. or_mask = RBIOS32(index);
  2676. index += 4;
  2677. val = RREG32(reg);
  2678. val = (val & and_mask) | or_mask;
  2679. WREG32(reg, val);
  2680. break;
  2681. case 4:
  2682. val = RBIOS16(index);
  2683. index += 2;
  2684. udelay(val);
  2685. break;
  2686. case 5:
  2687. reg = id & 0x1fff;
  2688. and_mask = RBIOS32(index);
  2689. index += 4;
  2690. or_mask = RBIOS32(index);
  2691. index += 4;
  2692. val = RREG32_PLL(reg);
  2693. val = (val & and_mask) | or_mask;
  2694. WREG32_PLL(reg, val);
  2695. break;
  2696. case 6:
  2697. reg = id & 0x1fff;
  2698. val = RBIOS8(index);
  2699. index += 1;
  2700. radeon_i2c_put_byte(tmds->i2c_bus,
  2701. tmds->slave_addr,
  2702. reg, val);
  2703. break;
  2704. default:
  2705. DRM_ERROR("Unknown id %d\n", id >> 13);
  2706. break;
  2707. }
  2708. id = RBIOS16(index);
  2709. }
  2710. return true;
  2711. }
  2712. }
  2713. return false;
  2714. }
  2715. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  2716. {
  2717. struct radeon_device *rdev = dev->dev_private;
  2718. if (offset) {
  2719. while (RBIOS16(offset)) {
  2720. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  2721. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  2722. uint32_t val, and_mask, or_mask;
  2723. uint32_t tmp;
  2724. offset += 2;
  2725. switch (cmd) {
  2726. case 0:
  2727. val = RBIOS32(offset);
  2728. offset += 4;
  2729. WREG32(addr, val);
  2730. break;
  2731. case 1:
  2732. val = RBIOS32(offset);
  2733. offset += 4;
  2734. WREG32(addr, val);
  2735. break;
  2736. case 2:
  2737. and_mask = RBIOS32(offset);
  2738. offset += 4;
  2739. or_mask = RBIOS32(offset);
  2740. offset += 4;
  2741. tmp = RREG32(addr);
  2742. tmp &= and_mask;
  2743. tmp |= or_mask;
  2744. WREG32(addr, tmp);
  2745. break;
  2746. case 3:
  2747. and_mask = RBIOS32(offset);
  2748. offset += 4;
  2749. or_mask = RBIOS32(offset);
  2750. offset += 4;
  2751. tmp = RREG32(addr);
  2752. tmp &= and_mask;
  2753. tmp |= or_mask;
  2754. WREG32(addr, tmp);
  2755. break;
  2756. case 4:
  2757. val = RBIOS16(offset);
  2758. offset += 2;
  2759. udelay(val);
  2760. break;
  2761. case 5:
  2762. val = RBIOS16(offset);
  2763. offset += 2;
  2764. switch (addr) {
  2765. case 8:
  2766. while (val--) {
  2767. if (!
  2768. (RREG32_PLL
  2769. (RADEON_CLK_PWRMGT_CNTL) &
  2770. RADEON_MC_BUSY))
  2771. break;
  2772. }
  2773. break;
  2774. case 9:
  2775. while (val--) {
  2776. if ((RREG32(RADEON_MC_STATUS) &
  2777. RADEON_MC_IDLE))
  2778. break;
  2779. }
  2780. break;
  2781. default:
  2782. break;
  2783. }
  2784. break;
  2785. default:
  2786. break;
  2787. }
  2788. }
  2789. }
  2790. }
  2791. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  2792. {
  2793. struct radeon_device *rdev = dev->dev_private;
  2794. if (offset) {
  2795. while (RBIOS8(offset)) {
  2796. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  2797. uint8_t addr = (RBIOS8(offset) & 0x3f);
  2798. uint32_t val, shift, tmp;
  2799. uint32_t and_mask, or_mask;
  2800. offset++;
  2801. switch (cmd) {
  2802. case 0:
  2803. val = RBIOS32(offset);
  2804. offset += 4;
  2805. WREG32_PLL(addr, val);
  2806. break;
  2807. case 1:
  2808. shift = RBIOS8(offset) * 8;
  2809. offset++;
  2810. and_mask = RBIOS8(offset) << shift;
  2811. and_mask |= ~(0xff << shift);
  2812. offset++;
  2813. or_mask = RBIOS8(offset) << shift;
  2814. offset++;
  2815. tmp = RREG32_PLL(addr);
  2816. tmp &= and_mask;
  2817. tmp |= or_mask;
  2818. WREG32_PLL(addr, tmp);
  2819. break;
  2820. case 2:
  2821. case 3:
  2822. tmp = 1000;
  2823. switch (addr) {
  2824. case 1:
  2825. udelay(150);
  2826. break;
  2827. case 2:
  2828. udelay(1000);
  2829. break;
  2830. case 3:
  2831. while (tmp--) {
  2832. if (!
  2833. (RREG32_PLL
  2834. (RADEON_CLK_PWRMGT_CNTL) &
  2835. RADEON_MC_BUSY))
  2836. break;
  2837. }
  2838. break;
  2839. case 4:
  2840. while (tmp--) {
  2841. if (RREG32_PLL
  2842. (RADEON_CLK_PWRMGT_CNTL) &
  2843. RADEON_DLL_READY)
  2844. break;
  2845. }
  2846. break;
  2847. case 5:
  2848. tmp =
  2849. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  2850. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  2851. #if 0
  2852. uint32_t mclk_cntl =
  2853. RREG32_PLL
  2854. (RADEON_MCLK_CNTL);
  2855. mclk_cntl &= 0xffff0000;
  2856. /*mclk_cntl |= 0x00001111;*//* ??? */
  2857. WREG32_PLL(RADEON_MCLK_CNTL,
  2858. mclk_cntl);
  2859. udelay(10000);
  2860. #endif
  2861. WREG32_PLL
  2862. (RADEON_CLK_PWRMGT_CNTL,
  2863. tmp &
  2864. ~RADEON_CG_NO1_DEBUG_0);
  2865. udelay(10000);
  2866. }
  2867. break;
  2868. default:
  2869. break;
  2870. }
  2871. break;
  2872. default:
  2873. break;
  2874. }
  2875. }
  2876. }
  2877. }
  2878. static void combios_parse_ram_reset_table(struct drm_device *dev,
  2879. uint16_t offset)
  2880. {
  2881. struct radeon_device *rdev = dev->dev_private;
  2882. uint32_t tmp;
  2883. if (offset) {
  2884. uint8_t val = RBIOS8(offset);
  2885. while (val != 0xff) {
  2886. offset++;
  2887. if (val == 0x0f) {
  2888. uint32_t channel_complete_mask;
  2889. if (ASIC_IS_R300(rdev))
  2890. channel_complete_mask =
  2891. R300_MEM_PWRUP_COMPLETE;
  2892. else
  2893. channel_complete_mask =
  2894. RADEON_MEM_PWRUP_COMPLETE;
  2895. tmp = 20000;
  2896. while (tmp--) {
  2897. if ((RREG32(RADEON_MEM_STR_CNTL) &
  2898. channel_complete_mask) ==
  2899. channel_complete_mask)
  2900. break;
  2901. }
  2902. } else {
  2903. uint32_t or_mask = RBIOS16(offset);
  2904. offset += 2;
  2905. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2906. tmp &= RADEON_SDRAM_MODE_MASK;
  2907. tmp |= or_mask;
  2908. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2909. or_mask = val << 24;
  2910. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2911. tmp &= RADEON_B3MEM_RESET_MASK;
  2912. tmp |= or_mask;
  2913. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2914. }
  2915. val = RBIOS8(offset);
  2916. }
  2917. }
  2918. }
  2919. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  2920. int mem_addr_mapping)
  2921. {
  2922. struct radeon_device *rdev = dev->dev_private;
  2923. uint32_t mem_cntl;
  2924. uint32_t mem_size;
  2925. uint32_t addr = 0;
  2926. mem_cntl = RREG32(RADEON_MEM_CNTL);
  2927. if (mem_cntl & RV100_HALF_MODE)
  2928. ram /= 2;
  2929. mem_size = ram;
  2930. mem_cntl &= ~(0xff << 8);
  2931. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  2932. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2933. RREG32(RADEON_MEM_CNTL);
  2934. /* sdram reset ? */
  2935. /* something like this???? */
  2936. while (ram--) {
  2937. addr = ram * 1024 * 1024;
  2938. /* write to each page */
  2939. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2940. WREG32(RADEON_MM_DATA, 0xdeadbeef);
  2941. /* read back and verify */
  2942. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2943. if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
  2944. return 0;
  2945. }
  2946. return mem_size;
  2947. }
  2948. static void combios_write_ram_size(struct drm_device *dev)
  2949. {
  2950. struct radeon_device *rdev = dev->dev_private;
  2951. uint8_t rev;
  2952. uint16_t offset;
  2953. uint32_t mem_size = 0;
  2954. uint32_t mem_cntl = 0;
  2955. /* should do something smarter here I guess... */
  2956. if (rdev->flags & RADEON_IS_IGP)
  2957. return;
  2958. /* first check detected mem table */
  2959. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  2960. if (offset) {
  2961. rev = RBIOS8(offset);
  2962. if (rev < 3) {
  2963. mem_cntl = RBIOS32(offset + 1);
  2964. mem_size = RBIOS16(offset + 5);
  2965. if ((rdev->family < CHIP_R200) &&
  2966. !ASIC_IS_RN50(rdev))
  2967. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2968. }
  2969. }
  2970. if (!mem_size) {
  2971. offset =
  2972. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  2973. if (offset) {
  2974. rev = RBIOS8(offset - 1);
  2975. if (rev < 1) {
  2976. if ((rdev->family < CHIP_R200)
  2977. && !ASIC_IS_RN50(rdev)) {
  2978. int ram = 0;
  2979. int mem_addr_mapping = 0;
  2980. while (RBIOS8(offset)) {
  2981. ram = RBIOS8(offset);
  2982. mem_addr_mapping =
  2983. RBIOS8(offset + 1);
  2984. if (mem_addr_mapping != 0x25)
  2985. ram *= 2;
  2986. mem_size =
  2987. combios_detect_ram(dev, ram,
  2988. mem_addr_mapping);
  2989. if (mem_size)
  2990. break;
  2991. offset += 2;
  2992. }
  2993. } else
  2994. mem_size = RBIOS8(offset);
  2995. } else {
  2996. mem_size = RBIOS8(offset);
  2997. mem_size *= 2; /* convert to MB */
  2998. }
  2999. }
  3000. }
  3001. mem_size *= (1024 * 1024); /* convert to bytes */
  3002. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  3003. }
  3004. void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
  3005. {
  3006. uint16_t dyn_clk_info =
  3007. combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3008. if (dyn_clk_info)
  3009. combios_parse_pll_table(dev, dyn_clk_info);
  3010. }
  3011. void radeon_combios_asic_init(struct drm_device *dev)
  3012. {
  3013. struct radeon_device *rdev = dev->dev_private;
  3014. uint16_t table;
  3015. /* port hardcoded mac stuff from radeonfb */
  3016. if (rdev->bios == NULL)
  3017. return;
  3018. /* ASIC INIT 1 */
  3019. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  3020. if (table)
  3021. combios_parse_mmio_table(dev, table);
  3022. /* PLL INIT */
  3023. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  3024. if (table)
  3025. combios_parse_pll_table(dev, table);
  3026. /* ASIC INIT 2 */
  3027. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  3028. if (table)
  3029. combios_parse_mmio_table(dev, table);
  3030. if (!(rdev->flags & RADEON_IS_IGP)) {
  3031. /* ASIC INIT 4 */
  3032. table =
  3033. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  3034. if (table)
  3035. combios_parse_mmio_table(dev, table);
  3036. /* RAM RESET */
  3037. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  3038. if (table)
  3039. combios_parse_ram_reset_table(dev, table);
  3040. /* ASIC INIT 3 */
  3041. table =
  3042. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  3043. if (table)
  3044. combios_parse_mmio_table(dev, table);
  3045. /* write CONFIG_MEMSIZE */
  3046. combios_write_ram_size(dev);
  3047. }
  3048. /* quirk for rs4xx HP nx6125 laptop to make it resume
  3049. * - it hangs on resume inside the dynclk 1 table.
  3050. */
  3051. if (rdev->family == CHIP_RS480 &&
  3052. rdev->pdev->subsystem_vendor == 0x103c &&
  3053. rdev->pdev->subsystem_device == 0x308b)
  3054. return;
  3055. /* quirk for rs4xx HP dv5000 laptop to make it resume
  3056. * - it hangs on resume inside the dynclk 1 table.
  3057. */
  3058. if (rdev->family == CHIP_RS480 &&
  3059. rdev->pdev->subsystem_vendor == 0x103c &&
  3060. rdev->pdev->subsystem_device == 0x30a4)
  3061. return;
  3062. /* DYN CLK 1 */
  3063. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3064. if (table)
  3065. combios_parse_pll_table(dev, table);
  3066. }
  3067. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  3068. {
  3069. struct radeon_device *rdev = dev->dev_private;
  3070. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  3071. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3072. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3073. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  3074. /* let the bios control the backlight */
  3075. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  3076. /* tell the bios not to handle mode switching */
  3077. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  3078. RADEON_ACC_MODE_CHANGE);
  3079. /* tell the bios a driver is loaded */
  3080. bios_7_scratch |= RADEON_DRV_LOADED;
  3081. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3082. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3083. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  3084. }
  3085. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  3086. {
  3087. struct drm_device *dev = encoder->dev;
  3088. struct radeon_device *rdev = dev->dev_private;
  3089. uint32_t bios_6_scratch;
  3090. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3091. if (lock)
  3092. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  3093. else
  3094. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  3095. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3096. }
  3097. void
  3098. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  3099. struct drm_encoder *encoder,
  3100. bool connected)
  3101. {
  3102. struct drm_device *dev = connector->dev;
  3103. struct radeon_device *rdev = dev->dev_private;
  3104. struct radeon_connector *radeon_connector =
  3105. to_radeon_connector(connector);
  3106. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3107. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  3108. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3109. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3110. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3111. if (connected) {
  3112. DRM_DEBUG_KMS("TV1 connected\n");
  3113. /* fix me */
  3114. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  3115. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  3116. bios_5_scratch |= RADEON_TV1_ON;
  3117. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  3118. } else {
  3119. DRM_DEBUG_KMS("TV1 disconnected\n");
  3120. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  3121. bios_5_scratch &= ~RADEON_TV1_ON;
  3122. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  3123. }
  3124. }
  3125. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3126. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3127. if (connected) {
  3128. DRM_DEBUG_KMS("LCD1 connected\n");
  3129. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  3130. bios_5_scratch |= RADEON_LCD1_ON;
  3131. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  3132. } else {
  3133. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3134. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  3135. bios_5_scratch &= ~RADEON_LCD1_ON;
  3136. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  3137. }
  3138. }
  3139. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3140. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3141. if (connected) {
  3142. DRM_DEBUG_KMS("CRT1 connected\n");
  3143. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  3144. bios_5_scratch |= RADEON_CRT1_ON;
  3145. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  3146. } else {
  3147. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3148. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  3149. bios_5_scratch &= ~RADEON_CRT1_ON;
  3150. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  3151. }
  3152. }
  3153. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3154. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3155. if (connected) {
  3156. DRM_DEBUG_KMS("CRT2 connected\n");
  3157. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  3158. bios_5_scratch |= RADEON_CRT2_ON;
  3159. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  3160. } else {
  3161. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3162. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  3163. bios_5_scratch &= ~RADEON_CRT2_ON;
  3164. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  3165. }
  3166. }
  3167. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3168. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3169. if (connected) {
  3170. DRM_DEBUG_KMS("DFP1 connected\n");
  3171. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  3172. bios_5_scratch |= RADEON_DFP1_ON;
  3173. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  3174. } else {
  3175. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3176. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  3177. bios_5_scratch &= ~RADEON_DFP1_ON;
  3178. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  3179. }
  3180. }
  3181. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3182. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3183. if (connected) {
  3184. DRM_DEBUG_KMS("DFP2 connected\n");
  3185. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  3186. bios_5_scratch |= RADEON_DFP2_ON;
  3187. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  3188. } else {
  3189. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3190. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  3191. bios_5_scratch &= ~RADEON_DFP2_ON;
  3192. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  3193. }
  3194. }
  3195. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  3196. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3197. }
  3198. void
  3199. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3200. {
  3201. struct drm_device *dev = encoder->dev;
  3202. struct radeon_device *rdev = dev->dev_private;
  3203. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3204. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3205. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3206. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  3207. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  3208. }
  3209. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3210. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  3211. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  3212. }
  3213. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3214. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  3215. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  3216. }
  3217. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3218. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  3219. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  3220. }
  3221. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3222. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  3223. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  3224. }
  3225. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3226. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  3227. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  3228. }
  3229. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3230. }
  3231. void
  3232. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3233. {
  3234. struct drm_device *dev = encoder->dev;
  3235. struct radeon_device *rdev = dev->dev_private;
  3236. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3237. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3238. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  3239. if (on)
  3240. bios_6_scratch |= RADEON_TV_DPMS_ON;
  3241. else
  3242. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  3243. }
  3244. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3245. if (on)
  3246. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  3247. else
  3248. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  3249. }
  3250. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3251. if (on)
  3252. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  3253. else
  3254. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  3255. }
  3256. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  3257. if (on)
  3258. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  3259. else
  3260. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  3261. }
  3262. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3263. }