radeon_combios.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538
  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_MASK_1;
  599. i2c.mask_data_mask = RADEON_GPIO_MASK_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. (rdev->family >= CHIP_R300)) {
  748. /* 0x68 */
  749. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  750. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  751. } else {
  752. /* 0x68 */
  753. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  754. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  755. /* 0x6c */
  756. i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  757. rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
  758. }
  759. }
  760. bool radeon_combios_get_clock_info(struct drm_device *dev)
  761. {
  762. struct radeon_device *rdev = dev->dev_private;
  763. uint16_t pll_info;
  764. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  765. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  766. struct radeon_pll *spll = &rdev->clock.spll;
  767. struct radeon_pll *mpll = &rdev->clock.mpll;
  768. int8_t rev;
  769. uint16_t sclk, mclk;
  770. pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
  771. if (pll_info) {
  772. rev = RBIOS8(pll_info);
  773. /* pixel clocks */
  774. p1pll->reference_freq = RBIOS16(pll_info + 0xe);
  775. p1pll->reference_div = RBIOS16(pll_info + 0x10);
  776. p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
  777. p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
  778. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  779. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  780. if (rev > 9) {
  781. p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
  782. p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
  783. } else {
  784. p1pll->pll_in_min = 40;
  785. p1pll->pll_in_max = 500;
  786. }
  787. *p2pll = *p1pll;
  788. /* system clock */
  789. spll->reference_freq = RBIOS16(pll_info + 0x1a);
  790. spll->reference_div = RBIOS16(pll_info + 0x1c);
  791. spll->pll_out_min = RBIOS32(pll_info + 0x1e);
  792. spll->pll_out_max = RBIOS32(pll_info + 0x22);
  793. if (rev > 10) {
  794. spll->pll_in_min = RBIOS32(pll_info + 0x48);
  795. spll->pll_in_max = RBIOS32(pll_info + 0x4c);
  796. } else {
  797. /* ??? */
  798. spll->pll_in_min = 40;
  799. spll->pll_in_max = 500;
  800. }
  801. /* memory clock */
  802. mpll->reference_freq = RBIOS16(pll_info + 0x26);
  803. mpll->reference_div = RBIOS16(pll_info + 0x28);
  804. mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
  805. mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
  806. if (rev > 10) {
  807. mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
  808. mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
  809. } else {
  810. /* ??? */
  811. mpll->pll_in_min = 40;
  812. mpll->pll_in_max = 500;
  813. }
  814. /* default sclk/mclk */
  815. sclk = RBIOS16(pll_info + 0xa);
  816. mclk = RBIOS16(pll_info + 0x8);
  817. if (sclk == 0)
  818. sclk = 200 * 100;
  819. if (mclk == 0)
  820. mclk = 200 * 100;
  821. rdev->clock.default_sclk = sclk;
  822. rdev->clock.default_mclk = mclk;
  823. if (RBIOS32(pll_info + 0x16))
  824. rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
  825. else
  826. rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
  827. return true;
  828. }
  829. return false;
  830. }
  831. bool radeon_combios_sideport_present(struct radeon_device *rdev)
  832. {
  833. struct drm_device *dev = rdev->ddev;
  834. u16 igp_info;
  835. /* sideport is AMD only */
  836. if (rdev->family == CHIP_RS400)
  837. return false;
  838. igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
  839. if (igp_info) {
  840. if (RBIOS16(igp_info + 0x4))
  841. return true;
  842. }
  843. return false;
  844. }
  845. static const uint32_t default_primarydac_adj[CHIP_LAST] = {
  846. 0x00000808, /* r100 */
  847. 0x00000808, /* rv100 */
  848. 0x00000808, /* rs100 */
  849. 0x00000808, /* rv200 */
  850. 0x00000808, /* rs200 */
  851. 0x00000808, /* r200 */
  852. 0x00000808, /* rv250 */
  853. 0x00000000, /* rs300 */
  854. 0x00000808, /* rv280 */
  855. 0x00000808, /* r300 */
  856. 0x00000808, /* r350 */
  857. 0x00000808, /* rv350 */
  858. 0x00000808, /* rv380 */
  859. 0x00000808, /* r420 */
  860. 0x00000808, /* r423 */
  861. 0x00000808, /* rv410 */
  862. 0x00000000, /* rs400 */
  863. 0x00000000, /* rs480 */
  864. };
  865. static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
  866. struct radeon_encoder_primary_dac *p_dac)
  867. {
  868. p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
  869. return;
  870. }
  871. struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
  872. radeon_encoder
  873. *encoder)
  874. {
  875. struct drm_device *dev = encoder->base.dev;
  876. struct radeon_device *rdev = dev->dev_private;
  877. uint16_t dac_info;
  878. uint8_t rev, bg, dac;
  879. struct radeon_encoder_primary_dac *p_dac = NULL;
  880. int found = 0;
  881. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
  882. GFP_KERNEL);
  883. if (!p_dac)
  884. return NULL;
  885. /* check CRT table */
  886. dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  887. if (dac_info) {
  888. rev = RBIOS8(dac_info) & 0x3;
  889. if (rev < 2) {
  890. bg = RBIOS8(dac_info + 0x2) & 0xf;
  891. dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
  892. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  893. } else {
  894. bg = RBIOS8(dac_info + 0x2) & 0xf;
  895. dac = RBIOS8(dac_info + 0x3) & 0xf;
  896. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  897. }
  898. /* if the values are all zeros, use the table */
  899. if (p_dac->ps2_pdac_adj)
  900. found = 1;
  901. }
  902. if (!found) /* fallback to defaults */
  903. radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
  904. return p_dac;
  905. }
  906. enum radeon_tv_std
  907. radeon_combios_get_tv_info(struct radeon_device *rdev)
  908. {
  909. struct drm_device *dev = rdev->ddev;
  910. uint16_t tv_info;
  911. enum radeon_tv_std tv_std = TV_STD_NTSC;
  912. tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  913. if (tv_info) {
  914. if (RBIOS8(tv_info + 6) == 'T') {
  915. switch (RBIOS8(tv_info + 7) & 0xf) {
  916. case 1:
  917. tv_std = TV_STD_NTSC;
  918. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  919. break;
  920. case 2:
  921. tv_std = TV_STD_PAL;
  922. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  923. break;
  924. case 3:
  925. tv_std = TV_STD_PAL_M;
  926. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  927. break;
  928. case 4:
  929. tv_std = TV_STD_PAL_60;
  930. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  931. break;
  932. case 5:
  933. tv_std = TV_STD_NTSC_J;
  934. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  935. break;
  936. case 6:
  937. tv_std = TV_STD_SCART_PAL;
  938. DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
  939. break;
  940. default:
  941. tv_std = TV_STD_NTSC;
  942. DRM_DEBUG_KMS
  943. ("Unknown TV standard; defaulting to NTSC\n");
  944. break;
  945. }
  946. switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
  947. case 0:
  948. DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
  949. break;
  950. case 1:
  951. DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
  952. break;
  953. case 2:
  954. DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
  955. break;
  956. case 3:
  957. DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
  958. break;
  959. default:
  960. break;
  961. }
  962. }
  963. }
  964. return tv_std;
  965. }
  966. static const uint32_t default_tvdac_adj[CHIP_LAST] = {
  967. 0x00000000, /* r100 */
  968. 0x00280000, /* rv100 */
  969. 0x00000000, /* rs100 */
  970. 0x00880000, /* rv200 */
  971. 0x00000000, /* rs200 */
  972. 0x00000000, /* r200 */
  973. 0x00770000, /* rv250 */
  974. 0x00290000, /* rs300 */
  975. 0x00560000, /* rv280 */
  976. 0x00780000, /* r300 */
  977. 0x00770000, /* r350 */
  978. 0x00780000, /* rv350 */
  979. 0x00780000, /* rv380 */
  980. 0x01080000, /* r420 */
  981. 0x01080000, /* r423 */
  982. 0x01080000, /* rv410 */
  983. 0x00780000, /* rs400 */
  984. 0x00780000, /* rs480 */
  985. };
  986. static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
  987. struct radeon_encoder_tv_dac *tv_dac)
  988. {
  989. tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
  990. if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
  991. tv_dac->ps2_tvdac_adj = 0x00880000;
  992. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  993. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  994. return;
  995. }
  996. struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
  997. radeon_encoder
  998. *encoder)
  999. {
  1000. struct drm_device *dev = encoder->base.dev;
  1001. struct radeon_device *rdev = dev->dev_private;
  1002. uint16_t dac_info;
  1003. uint8_t rev, bg, dac;
  1004. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1005. int found = 0;
  1006. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1007. if (!tv_dac)
  1008. return NULL;
  1009. /* first check TV table */
  1010. dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  1011. if (dac_info) {
  1012. rev = RBIOS8(dac_info + 0x3);
  1013. if (rev > 4) {
  1014. bg = RBIOS8(dac_info + 0xc) & 0xf;
  1015. dac = RBIOS8(dac_info + 0xd) & 0xf;
  1016. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1017. bg = RBIOS8(dac_info + 0xe) & 0xf;
  1018. dac = RBIOS8(dac_info + 0xf) & 0xf;
  1019. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1020. bg = RBIOS8(dac_info + 0x10) & 0xf;
  1021. dac = RBIOS8(dac_info + 0x11) & 0xf;
  1022. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1023. /* if the values are all zeros, use the table */
  1024. if (tv_dac->ps2_tvdac_adj)
  1025. found = 1;
  1026. } else if (rev > 1) {
  1027. bg = RBIOS8(dac_info + 0xc) & 0xf;
  1028. dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
  1029. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1030. bg = RBIOS8(dac_info + 0xd) & 0xf;
  1031. dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
  1032. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1033. bg = RBIOS8(dac_info + 0xe) & 0xf;
  1034. dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
  1035. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1036. /* if the values are all zeros, use the table */
  1037. if (tv_dac->ps2_tvdac_adj)
  1038. found = 1;
  1039. }
  1040. tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
  1041. }
  1042. if (!found) {
  1043. /* then check CRT table */
  1044. dac_info =
  1045. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  1046. if (dac_info) {
  1047. rev = RBIOS8(dac_info) & 0x3;
  1048. if (rev < 2) {
  1049. bg = RBIOS8(dac_info + 0x3) & 0xf;
  1050. dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
  1051. tv_dac->ps2_tvdac_adj =
  1052. (bg << 16) | (dac << 20);
  1053. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1054. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1055. /* if the values are all zeros, use the table */
  1056. if (tv_dac->ps2_tvdac_adj)
  1057. found = 1;
  1058. } else {
  1059. bg = RBIOS8(dac_info + 0x4) & 0xf;
  1060. dac = RBIOS8(dac_info + 0x5) & 0xf;
  1061. tv_dac->ps2_tvdac_adj =
  1062. (bg << 16) | (dac << 20);
  1063. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1064. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1065. /* if the values are all zeros, use the table */
  1066. if (tv_dac->ps2_tvdac_adj)
  1067. found = 1;
  1068. }
  1069. } else {
  1070. DRM_INFO("No TV DAC info found in BIOS\n");
  1071. }
  1072. }
  1073. if (!found) /* fallback to defaults */
  1074. radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
  1075. return tv_dac;
  1076. }
  1077. static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
  1078. radeon_device
  1079. *rdev)
  1080. {
  1081. struct radeon_encoder_lvds *lvds = NULL;
  1082. uint32_t fp_vert_stretch, fp_horz_stretch;
  1083. uint32_t ppll_div_sel, ppll_val;
  1084. uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
  1085. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1086. if (!lvds)
  1087. return NULL;
  1088. fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
  1089. fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
  1090. /* These should be fail-safe defaults, fingers crossed */
  1091. lvds->panel_pwr_delay = 200;
  1092. lvds->panel_vcc_delay = 2000;
  1093. lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  1094. lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
  1095. lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
  1096. if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
  1097. lvds->native_mode.vdisplay =
  1098. ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
  1099. RADEON_VERT_PANEL_SHIFT) + 1;
  1100. else
  1101. lvds->native_mode.vdisplay =
  1102. (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
  1103. if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
  1104. lvds->native_mode.hdisplay =
  1105. (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
  1106. RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
  1107. else
  1108. lvds->native_mode.hdisplay =
  1109. ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
  1110. if ((lvds->native_mode.hdisplay < 640) ||
  1111. (lvds->native_mode.vdisplay < 480)) {
  1112. lvds->native_mode.hdisplay = 640;
  1113. lvds->native_mode.vdisplay = 480;
  1114. }
  1115. ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
  1116. ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
  1117. if ((ppll_val & 0x000707ff) == 0x1bb)
  1118. lvds->use_bios_dividers = false;
  1119. else {
  1120. lvds->panel_ref_divider =
  1121. RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  1122. lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
  1123. lvds->panel_fb_divider = ppll_val & 0x7ff;
  1124. if ((lvds->panel_ref_divider != 0) &&
  1125. (lvds->panel_fb_divider > 3))
  1126. lvds->use_bios_dividers = true;
  1127. }
  1128. lvds->panel_vcc_delay = 200;
  1129. DRM_INFO("Panel info derived from registers\n");
  1130. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1131. lvds->native_mode.vdisplay);
  1132. return lvds;
  1133. }
  1134. struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
  1135. *encoder)
  1136. {
  1137. struct drm_device *dev = encoder->base.dev;
  1138. struct radeon_device *rdev = dev->dev_private;
  1139. uint16_t lcd_info;
  1140. uint32_t panel_setup;
  1141. char stmp[30];
  1142. int tmp, i;
  1143. struct radeon_encoder_lvds *lvds = NULL;
  1144. lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  1145. if (lcd_info) {
  1146. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1147. if (!lvds)
  1148. return NULL;
  1149. for (i = 0; i < 24; i++)
  1150. stmp[i] = RBIOS8(lcd_info + i + 1);
  1151. stmp[24] = 0;
  1152. DRM_INFO("Panel ID String: %s\n", stmp);
  1153. lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
  1154. lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
  1155. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1156. lvds->native_mode.vdisplay);
  1157. lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
  1158. lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
  1159. lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
  1160. lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
  1161. lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
  1162. lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
  1163. lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
  1164. lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
  1165. if ((lvds->panel_ref_divider != 0) &&
  1166. (lvds->panel_fb_divider > 3))
  1167. lvds->use_bios_dividers = true;
  1168. panel_setup = RBIOS32(lcd_info + 0x39);
  1169. lvds->lvds_gen_cntl = 0xff00;
  1170. if (panel_setup & 0x1)
  1171. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
  1172. if ((panel_setup >> 4) & 0x1)
  1173. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
  1174. switch ((panel_setup >> 8) & 0x7) {
  1175. case 0:
  1176. lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
  1177. break;
  1178. case 1:
  1179. lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
  1180. break;
  1181. case 2:
  1182. lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
  1183. break;
  1184. default:
  1185. break;
  1186. }
  1187. if ((panel_setup >> 16) & 0x1)
  1188. lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
  1189. if ((panel_setup >> 17) & 0x1)
  1190. lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
  1191. if ((panel_setup >> 18) & 0x1)
  1192. lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
  1193. if ((panel_setup >> 23) & 0x1)
  1194. lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
  1195. lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
  1196. for (i = 0; i < 32; i++) {
  1197. tmp = RBIOS16(lcd_info + 64 + i * 2);
  1198. if (tmp == 0)
  1199. break;
  1200. if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
  1201. (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
  1202. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1203. (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
  1204. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1205. (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
  1206. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1207. (RBIOS8(tmp + 23) * 8);
  1208. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1209. (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
  1210. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1211. ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
  1212. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1213. ((RBIOS16(tmp + 28) & 0xf800) >> 11);
  1214. lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
  1215. lvds->native_mode.flags = 0;
  1216. /* set crtc values */
  1217. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1218. }
  1219. }
  1220. } else {
  1221. DRM_INFO("No panel info found in BIOS\n");
  1222. lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
  1223. }
  1224. if (lvds)
  1225. encoder->native_mode = lvds->native_mode;
  1226. return lvds;
  1227. }
  1228. static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
  1229. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
  1230. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
  1231. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
  1232. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
  1233. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
  1234. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
  1235. {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
  1236. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
  1237. {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
  1238. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
  1239. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
  1240. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
  1241. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
  1242. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
  1243. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
  1244. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
  1245. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
  1246. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
  1247. };
  1248. bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
  1249. struct radeon_encoder_int_tmds *tmds)
  1250. {
  1251. struct drm_device *dev = encoder->base.dev;
  1252. struct radeon_device *rdev = dev->dev_private;
  1253. int i;
  1254. for (i = 0; i < 4; i++) {
  1255. tmds->tmds_pll[i].value =
  1256. default_tmds_pll[rdev->family][i].value;
  1257. tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
  1258. }
  1259. return true;
  1260. }
  1261. bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
  1262. struct radeon_encoder_int_tmds *tmds)
  1263. {
  1264. struct drm_device *dev = encoder->base.dev;
  1265. struct radeon_device *rdev = dev->dev_private;
  1266. uint16_t tmds_info;
  1267. int i, n;
  1268. uint8_t ver;
  1269. tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  1270. if (tmds_info) {
  1271. ver = RBIOS8(tmds_info);
  1272. DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
  1273. if (ver == 3) {
  1274. n = RBIOS8(tmds_info + 5) + 1;
  1275. if (n > 4)
  1276. n = 4;
  1277. for (i = 0; i < n; i++) {
  1278. tmds->tmds_pll[i].value =
  1279. RBIOS32(tmds_info + i * 10 + 0x08);
  1280. tmds->tmds_pll[i].freq =
  1281. RBIOS16(tmds_info + i * 10 + 0x10);
  1282. DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
  1283. tmds->tmds_pll[i].freq,
  1284. tmds->tmds_pll[i].value);
  1285. }
  1286. } else if (ver == 4) {
  1287. int stride = 0;
  1288. n = RBIOS8(tmds_info + 5) + 1;
  1289. if (n > 4)
  1290. n = 4;
  1291. for (i = 0; i < n; i++) {
  1292. tmds->tmds_pll[i].value =
  1293. RBIOS32(tmds_info + stride + 0x08);
  1294. tmds->tmds_pll[i].freq =
  1295. RBIOS16(tmds_info + stride + 0x10);
  1296. if (i == 0)
  1297. stride += 10;
  1298. else
  1299. stride += 6;
  1300. DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
  1301. tmds->tmds_pll[i].freq,
  1302. tmds->tmds_pll[i].value);
  1303. }
  1304. }
  1305. } else {
  1306. DRM_INFO("No TMDS info found in BIOS\n");
  1307. return false;
  1308. }
  1309. return true;
  1310. }
  1311. bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
  1312. struct radeon_encoder_ext_tmds *tmds)
  1313. {
  1314. struct drm_device *dev = encoder->base.dev;
  1315. struct radeon_device *rdev = dev->dev_private;
  1316. struct radeon_i2c_bus_rec i2c_bus;
  1317. /* default for macs */
  1318. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1319. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1320. /* XXX some macs have duallink chips */
  1321. switch (rdev->mode_info.connector_table) {
  1322. case CT_POWERBOOK_EXTERNAL:
  1323. case CT_MINI_EXTERNAL:
  1324. default:
  1325. tmds->dvo_chip = DVO_SIL164;
  1326. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1327. break;
  1328. }
  1329. return true;
  1330. }
  1331. bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
  1332. struct radeon_encoder_ext_tmds *tmds)
  1333. {
  1334. struct drm_device *dev = encoder->base.dev;
  1335. struct radeon_device *rdev = dev->dev_private;
  1336. uint16_t offset;
  1337. uint8_t ver;
  1338. enum radeon_combios_ddc gpio;
  1339. struct radeon_i2c_bus_rec i2c_bus;
  1340. tmds->i2c_bus = NULL;
  1341. if (rdev->flags & RADEON_IS_IGP) {
  1342. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1343. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1344. tmds->dvo_chip = DVO_SIL164;
  1345. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1346. } else {
  1347. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  1348. if (offset) {
  1349. ver = RBIOS8(offset);
  1350. DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
  1351. tmds->slave_addr = RBIOS8(offset + 4 + 2);
  1352. tmds->slave_addr >>= 1; /* 7 bit addressing */
  1353. gpio = RBIOS8(offset + 4 + 3);
  1354. if (gpio == DDC_LCD) {
  1355. /* MM i2c */
  1356. i2c_bus.valid = true;
  1357. i2c_bus.hw_capable = true;
  1358. i2c_bus.mm_i2c = true;
  1359. i2c_bus.i2c_id = 0xa0;
  1360. } else
  1361. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  1362. tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1363. }
  1364. }
  1365. if (!tmds->i2c_bus) {
  1366. DRM_INFO("No valid Ext TMDS info found in BIOS\n");
  1367. return false;
  1368. }
  1369. return true;
  1370. }
  1371. bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
  1372. {
  1373. struct radeon_device *rdev = dev->dev_private;
  1374. struct radeon_i2c_bus_rec ddc_i2c;
  1375. struct radeon_hpd hpd;
  1376. rdev->mode_info.connector_table = radeon_connector_table;
  1377. if (rdev->mode_info.connector_table == CT_NONE) {
  1378. #ifdef CONFIG_PPC_PMAC
  1379. if (of_machine_is_compatible("PowerBook3,3")) {
  1380. /* powerbook with VGA */
  1381. rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
  1382. } else if (of_machine_is_compatible("PowerBook3,4") ||
  1383. of_machine_is_compatible("PowerBook3,5")) {
  1384. /* powerbook with internal tmds */
  1385. rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
  1386. } else if (of_machine_is_compatible("PowerBook5,1") ||
  1387. of_machine_is_compatible("PowerBook5,2") ||
  1388. of_machine_is_compatible("PowerBook5,3") ||
  1389. of_machine_is_compatible("PowerBook5,4") ||
  1390. of_machine_is_compatible("PowerBook5,5")) {
  1391. /* powerbook with external single link tmds (sil164) */
  1392. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1393. } else if (of_machine_is_compatible("PowerBook5,6")) {
  1394. /* powerbook with external dual or single link tmds */
  1395. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1396. } else if (of_machine_is_compatible("PowerBook5,7") ||
  1397. of_machine_is_compatible("PowerBook5,8") ||
  1398. of_machine_is_compatible("PowerBook5,9")) {
  1399. /* PowerBook6,2 ? */
  1400. /* powerbook with external dual link tmds (sil1178?) */
  1401. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1402. } else if (of_machine_is_compatible("PowerBook4,1") ||
  1403. of_machine_is_compatible("PowerBook4,2") ||
  1404. of_machine_is_compatible("PowerBook4,3") ||
  1405. of_machine_is_compatible("PowerBook6,3") ||
  1406. of_machine_is_compatible("PowerBook6,5") ||
  1407. of_machine_is_compatible("PowerBook6,7")) {
  1408. /* ibook */
  1409. rdev->mode_info.connector_table = CT_IBOOK;
  1410. } else if (of_machine_is_compatible("PowerMac4,4")) {
  1411. /* emac */
  1412. rdev->mode_info.connector_table = CT_EMAC;
  1413. } else if (of_machine_is_compatible("PowerMac10,1")) {
  1414. /* mini with internal tmds */
  1415. rdev->mode_info.connector_table = CT_MINI_INTERNAL;
  1416. } else if (of_machine_is_compatible("PowerMac10,2")) {
  1417. /* mini with external tmds */
  1418. rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
  1419. } else if (of_machine_is_compatible("PowerMac12,1")) {
  1420. /* PowerMac8,1 ? */
  1421. /* imac g5 isight */
  1422. rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
  1423. } else if ((rdev->pdev->device == 0x4a48) &&
  1424. (rdev->pdev->subsystem_vendor == 0x1002) &&
  1425. (rdev->pdev->subsystem_device == 0x4a48)) {
  1426. /* Mac X800 */
  1427. rdev->mode_info.connector_table = CT_MAC_X800;
  1428. } else if ((of_machine_is_compatible("PowerMac7,2") ||
  1429. of_machine_is_compatible("PowerMac7,3")) &&
  1430. (rdev->pdev->device == 0x4150) &&
  1431. (rdev->pdev->subsystem_vendor == 0x1002) &&
  1432. (rdev->pdev->subsystem_device == 0x4150)) {
  1433. /* Mac G5 tower 9600 */
  1434. rdev->mode_info.connector_table = CT_MAC_G5_9600;
  1435. } else
  1436. #endif /* CONFIG_PPC_PMAC */
  1437. #ifdef CONFIG_PPC64
  1438. if (ASIC_IS_RN50(rdev))
  1439. rdev->mode_info.connector_table = CT_RN50_POWER;
  1440. else
  1441. #endif
  1442. rdev->mode_info.connector_table = CT_GENERIC;
  1443. }
  1444. switch (rdev->mode_info.connector_table) {
  1445. case CT_GENERIC:
  1446. DRM_INFO("Connector Table: %d (generic)\n",
  1447. rdev->mode_info.connector_table);
  1448. /* these are the most common settings */
  1449. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1450. /* VGA - primary dac */
  1451. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1452. hpd.hpd = RADEON_HPD_NONE;
  1453. radeon_add_legacy_encoder(dev,
  1454. radeon_get_encoder_enum(dev,
  1455. ATOM_DEVICE_CRT1_SUPPORT,
  1456. 1),
  1457. ATOM_DEVICE_CRT1_SUPPORT);
  1458. radeon_add_legacy_connector(dev, 0,
  1459. ATOM_DEVICE_CRT1_SUPPORT,
  1460. DRM_MODE_CONNECTOR_VGA,
  1461. &ddc_i2c,
  1462. CONNECTOR_OBJECT_ID_VGA,
  1463. &hpd);
  1464. } else if (rdev->flags & RADEON_IS_MOBILITY) {
  1465. /* LVDS */
  1466. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
  1467. hpd.hpd = RADEON_HPD_NONE;
  1468. radeon_add_legacy_encoder(dev,
  1469. radeon_get_encoder_enum(dev,
  1470. ATOM_DEVICE_LCD1_SUPPORT,
  1471. 0),
  1472. ATOM_DEVICE_LCD1_SUPPORT);
  1473. radeon_add_legacy_connector(dev, 0,
  1474. ATOM_DEVICE_LCD1_SUPPORT,
  1475. DRM_MODE_CONNECTOR_LVDS,
  1476. &ddc_i2c,
  1477. CONNECTOR_OBJECT_ID_LVDS,
  1478. &hpd);
  1479. /* VGA - primary dac */
  1480. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1481. hpd.hpd = RADEON_HPD_NONE;
  1482. radeon_add_legacy_encoder(dev,
  1483. radeon_get_encoder_enum(dev,
  1484. ATOM_DEVICE_CRT1_SUPPORT,
  1485. 1),
  1486. ATOM_DEVICE_CRT1_SUPPORT);
  1487. radeon_add_legacy_connector(dev, 1,
  1488. ATOM_DEVICE_CRT1_SUPPORT,
  1489. DRM_MODE_CONNECTOR_VGA,
  1490. &ddc_i2c,
  1491. CONNECTOR_OBJECT_ID_VGA,
  1492. &hpd);
  1493. } else {
  1494. /* DVI-I - tv dac, int tmds */
  1495. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1496. hpd.hpd = RADEON_HPD_1;
  1497. radeon_add_legacy_encoder(dev,
  1498. radeon_get_encoder_enum(dev,
  1499. ATOM_DEVICE_DFP1_SUPPORT,
  1500. 0),
  1501. ATOM_DEVICE_DFP1_SUPPORT);
  1502. radeon_add_legacy_encoder(dev,
  1503. radeon_get_encoder_enum(dev,
  1504. ATOM_DEVICE_CRT2_SUPPORT,
  1505. 2),
  1506. ATOM_DEVICE_CRT2_SUPPORT);
  1507. radeon_add_legacy_connector(dev, 0,
  1508. ATOM_DEVICE_DFP1_SUPPORT |
  1509. ATOM_DEVICE_CRT2_SUPPORT,
  1510. DRM_MODE_CONNECTOR_DVII,
  1511. &ddc_i2c,
  1512. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1513. &hpd);
  1514. /* VGA - primary dac */
  1515. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1516. hpd.hpd = RADEON_HPD_NONE;
  1517. radeon_add_legacy_encoder(dev,
  1518. radeon_get_encoder_enum(dev,
  1519. ATOM_DEVICE_CRT1_SUPPORT,
  1520. 1),
  1521. ATOM_DEVICE_CRT1_SUPPORT);
  1522. radeon_add_legacy_connector(dev, 1,
  1523. ATOM_DEVICE_CRT1_SUPPORT,
  1524. DRM_MODE_CONNECTOR_VGA,
  1525. &ddc_i2c,
  1526. CONNECTOR_OBJECT_ID_VGA,
  1527. &hpd);
  1528. }
  1529. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1530. /* TV - tv dac */
  1531. ddc_i2c.valid = false;
  1532. hpd.hpd = RADEON_HPD_NONE;
  1533. radeon_add_legacy_encoder(dev,
  1534. radeon_get_encoder_enum(dev,
  1535. ATOM_DEVICE_TV1_SUPPORT,
  1536. 2),
  1537. ATOM_DEVICE_TV1_SUPPORT);
  1538. radeon_add_legacy_connector(dev, 2,
  1539. ATOM_DEVICE_TV1_SUPPORT,
  1540. DRM_MODE_CONNECTOR_SVIDEO,
  1541. &ddc_i2c,
  1542. CONNECTOR_OBJECT_ID_SVIDEO,
  1543. &hpd);
  1544. }
  1545. break;
  1546. case CT_IBOOK:
  1547. DRM_INFO("Connector Table: %d (ibook)\n",
  1548. rdev->mode_info.connector_table);
  1549. /* LVDS */
  1550. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1551. hpd.hpd = RADEON_HPD_NONE;
  1552. radeon_add_legacy_encoder(dev,
  1553. radeon_get_encoder_enum(dev,
  1554. ATOM_DEVICE_LCD1_SUPPORT,
  1555. 0),
  1556. ATOM_DEVICE_LCD1_SUPPORT);
  1557. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1558. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1559. CONNECTOR_OBJECT_ID_LVDS,
  1560. &hpd);
  1561. /* VGA - TV DAC */
  1562. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1563. hpd.hpd = RADEON_HPD_NONE;
  1564. radeon_add_legacy_encoder(dev,
  1565. radeon_get_encoder_enum(dev,
  1566. ATOM_DEVICE_CRT2_SUPPORT,
  1567. 2),
  1568. ATOM_DEVICE_CRT2_SUPPORT);
  1569. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1570. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1571. CONNECTOR_OBJECT_ID_VGA,
  1572. &hpd);
  1573. /* TV - TV DAC */
  1574. ddc_i2c.valid = false;
  1575. hpd.hpd = RADEON_HPD_NONE;
  1576. radeon_add_legacy_encoder(dev,
  1577. radeon_get_encoder_enum(dev,
  1578. ATOM_DEVICE_TV1_SUPPORT,
  1579. 2),
  1580. ATOM_DEVICE_TV1_SUPPORT);
  1581. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1582. DRM_MODE_CONNECTOR_SVIDEO,
  1583. &ddc_i2c,
  1584. CONNECTOR_OBJECT_ID_SVIDEO,
  1585. &hpd);
  1586. break;
  1587. case CT_POWERBOOK_EXTERNAL:
  1588. DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
  1589. rdev->mode_info.connector_table);
  1590. /* LVDS */
  1591. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1592. hpd.hpd = RADEON_HPD_NONE;
  1593. radeon_add_legacy_encoder(dev,
  1594. radeon_get_encoder_enum(dev,
  1595. ATOM_DEVICE_LCD1_SUPPORT,
  1596. 0),
  1597. ATOM_DEVICE_LCD1_SUPPORT);
  1598. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1599. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1600. CONNECTOR_OBJECT_ID_LVDS,
  1601. &hpd);
  1602. /* DVI-I - primary dac, ext tmds */
  1603. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1604. hpd.hpd = RADEON_HPD_2; /* ??? */
  1605. radeon_add_legacy_encoder(dev,
  1606. radeon_get_encoder_enum(dev,
  1607. ATOM_DEVICE_DFP2_SUPPORT,
  1608. 0),
  1609. ATOM_DEVICE_DFP2_SUPPORT);
  1610. radeon_add_legacy_encoder(dev,
  1611. radeon_get_encoder_enum(dev,
  1612. ATOM_DEVICE_CRT1_SUPPORT,
  1613. 1),
  1614. ATOM_DEVICE_CRT1_SUPPORT);
  1615. /* XXX some are SL */
  1616. radeon_add_legacy_connector(dev, 1,
  1617. ATOM_DEVICE_DFP2_SUPPORT |
  1618. ATOM_DEVICE_CRT1_SUPPORT,
  1619. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1620. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1621. &hpd);
  1622. /* TV - TV DAC */
  1623. ddc_i2c.valid = false;
  1624. hpd.hpd = RADEON_HPD_NONE;
  1625. radeon_add_legacy_encoder(dev,
  1626. radeon_get_encoder_enum(dev,
  1627. ATOM_DEVICE_TV1_SUPPORT,
  1628. 2),
  1629. ATOM_DEVICE_TV1_SUPPORT);
  1630. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1631. DRM_MODE_CONNECTOR_SVIDEO,
  1632. &ddc_i2c,
  1633. CONNECTOR_OBJECT_ID_SVIDEO,
  1634. &hpd);
  1635. break;
  1636. case CT_POWERBOOK_INTERNAL:
  1637. DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
  1638. rdev->mode_info.connector_table);
  1639. /* LVDS */
  1640. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1641. hpd.hpd = RADEON_HPD_NONE;
  1642. radeon_add_legacy_encoder(dev,
  1643. radeon_get_encoder_enum(dev,
  1644. ATOM_DEVICE_LCD1_SUPPORT,
  1645. 0),
  1646. ATOM_DEVICE_LCD1_SUPPORT);
  1647. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1648. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1649. CONNECTOR_OBJECT_ID_LVDS,
  1650. &hpd);
  1651. /* DVI-I - primary dac, int tmds */
  1652. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1653. hpd.hpd = RADEON_HPD_1; /* ??? */
  1654. radeon_add_legacy_encoder(dev,
  1655. radeon_get_encoder_enum(dev,
  1656. ATOM_DEVICE_DFP1_SUPPORT,
  1657. 0),
  1658. ATOM_DEVICE_DFP1_SUPPORT);
  1659. radeon_add_legacy_encoder(dev,
  1660. radeon_get_encoder_enum(dev,
  1661. ATOM_DEVICE_CRT1_SUPPORT,
  1662. 1),
  1663. ATOM_DEVICE_CRT1_SUPPORT);
  1664. radeon_add_legacy_connector(dev, 1,
  1665. ATOM_DEVICE_DFP1_SUPPORT |
  1666. ATOM_DEVICE_CRT1_SUPPORT,
  1667. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1668. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1669. &hpd);
  1670. /* TV - TV DAC */
  1671. ddc_i2c.valid = false;
  1672. hpd.hpd = RADEON_HPD_NONE;
  1673. radeon_add_legacy_encoder(dev,
  1674. radeon_get_encoder_enum(dev,
  1675. ATOM_DEVICE_TV1_SUPPORT,
  1676. 2),
  1677. ATOM_DEVICE_TV1_SUPPORT);
  1678. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1679. DRM_MODE_CONNECTOR_SVIDEO,
  1680. &ddc_i2c,
  1681. CONNECTOR_OBJECT_ID_SVIDEO,
  1682. &hpd);
  1683. break;
  1684. case CT_POWERBOOK_VGA:
  1685. DRM_INFO("Connector Table: %d (powerbook vga)\n",
  1686. rdev->mode_info.connector_table);
  1687. /* LVDS */
  1688. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1689. hpd.hpd = RADEON_HPD_NONE;
  1690. radeon_add_legacy_encoder(dev,
  1691. radeon_get_encoder_enum(dev,
  1692. ATOM_DEVICE_LCD1_SUPPORT,
  1693. 0),
  1694. ATOM_DEVICE_LCD1_SUPPORT);
  1695. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1696. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1697. CONNECTOR_OBJECT_ID_LVDS,
  1698. &hpd);
  1699. /* VGA - primary dac */
  1700. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1701. hpd.hpd = RADEON_HPD_NONE;
  1702. radeon_add_legacy_encoder(dev,
  1703. radeon_get_encoder_enum(dev,
  1704. ATOM_DEVICE_CRT1_SUPPORT,
  1705. 1),
  1706. ATOM_DEVICE_CRT1_SUPPORT);
  1707. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
  1708. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1709. CONNECTOR_OBJECT_ID_VGA,
  1710. &hpd);
  1711. /* TV - TV DAC */
  1712. ddc_i2c.valid = false;
  1713. hpd.hpd = RADEON_HPD_NONE;
  1714. radeon_add_legacy_encoder(dev,
  1715. radeon_get_encoder_enum(dev,
  1716. ATOM_DEVICE_TV1_SUPPORT,
  1717. 2),
  1718. ATOM_DEVICE_TV1_SUPPORT);
  1719. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1720. DRM_MODE_CONNECTOR_SVIDEO,
  1721. &ddc_i2c,
  1722. CONNECTOR_OBJECT_ID_SVIDEO,
  1723. &hpd);
  1724. break;
  1725. case CT_MINI_EXTERNAL:
  1726. DRM_INFO("Connector Table: %d (mini external tmds)\n",
  1727. rdev->mode_info.connector_table);
  1728. /* DVI-I - tv dac, ext tmds */
  1729. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1730. hpd.hpd = RADEON_HPD_2; /* ??? */
  1731. radeon_add_legacy_encoder(dev,
  1732. radeon_get_encoder_enum(dev,
  1733. ATOM_DEVICE_DFP2_SUPPORT,
  1734. 0),
  1735. ATOM_DEVICE_DFP2_SUPPORT);
  1736. radeon_add_legacy_encoder(dev,
  1737. radeon_get_encoder_enum(dev,
  1738. ATOM_DEVICE_CRT2_SUPPORT,
  1739. 2),
  1740. ATOM_DEVICE_CRT2_SUPPORT);
  1741. /* XXX are any DL? */
  1742. radeon_add_legacy_connector(dev, 0,
  1743. ATOM_DEVICE_DFP2_SUPPORT |
  1744. ATOM_DEVICE_CRT2_SUPPORT,
  1745. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1746. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1747. &hpd);
  1748. /* TV - TV DAC */
  1749. ddc_i2c.valid = false;
  1750. hpd.hpd = RADEON_HPD_NONE;
  1751. radeon_add_legacy_encoder(dev,
  1752. radeon_get_encoder_enum(dev,
  1753. ATOM_DEVICE_TV1_SUPPORT,
  1754. 2),
  1755. ATOM_DEVICE_TV1_SUPPORT);
  1756. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1757. DRM_MODE_CONNECTOR_SVIDEO,
  1758. &ddc_i2c,
  1759. CONNECTOR_OBJECT_ID_SVIDEO,
  1760. &hpd);
  1761. break;
  1762. case CT_MINI_INTERNAL:
  1763. DRM_INFO("Connector Table: %d (mini internal tmds)\n",
  1764. rdev->mode_info.connector_table);
  1765. /* DVI-I - tv dac, int tmds */
  1766. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1767. hpd.hpd = RADEON_HPD_1; /* ??? */
  1768. radeon_add_legacy_encoder(dev,
  1769. radeon_get_encoder_enum(dev,
  1770. ATOM_DEVICE_DFP1_SUPPORT,
  1771. 0),
  1772. ATOM_DEVICE_DFP1_SUPPORT);
  1773. radeon_add_legacy_encoder(dev,
  1774. radeon_get_encoder_enum(dev,
  1775. ATOM_DEVICE_CRT2_SUPPORT,
  1776. 2),
  1777. ATOM_DEVICE_CRT2_SUPPORT);
  1778. radeon_add_legacy_connector(dev, 0,
  1779. ATOM_DEVICE_DFP1_SUPPORT |
  1780. ATOM_DEVICE_CRT2_SUPPORT,
  1781. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1782. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1783. &hpd);
  1784. /* TV - TV DAC */
  1785. ddc_i2c.valid = false;
  1786. hpd.hpd = RADEON_HPD_NONE;
  1787. radeon_add_legacy_encoder(dev,
  1788. radeon_get_encoder_enum(dev,
  1789. ATOM_DEVICE_TV1_SUPPORT,
  1790. 2),
  1791. ATOM_DEVICE_TV1_SUPPORT);
  1792. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1793. DRM_MODE_CONNECTOR_SVIDEO,
  1794. &ddc_i2c,
  1795. CONNECTOR_OBJECT_ID_SVIDEO,
  1796. &hpd);
  1797. break;
  1798. case CT_IMAC_G5_ISIGHT:
  1799. DRM_INFO("Connector Table: %d (imac g5 isight)\n",
  1800. rdev->mode_info.connector_table);
  1801. /* DVI-D - int tmds */
  1802. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1803. hpd.hpd = RADEON_HPD_1; /* ??? */
  1804. radeon_add_legacy_encoder(dev,
  1805. radeon_get_encoder_enum(dev,
  1806. ATOM_DEVICE_DFP1_SUPPORT,
  1807. 0),
  1808. ATOM_DEVICE_DFP1_SUPPORT);
  1809. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
  1810. DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
  1811. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  1812. &hpd);
  1813. /* VGA - tv dac */
  1814. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1815. hpd.hpd = RADEON_HPD_NONE;
  1816. radeon_add_legacy_encoder(dev,
  1817. radeon_get_encoder_enum(dev,
  1818. ATOM_DEVICE_CRT2_SUPPORT,
  1819. 2),
  1820. ATOM_DEVICE_CRT2_SUPPORT);
  1821. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1822. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1823. CONNECTOR_OBJECT_ID_VGA,
  1824. &hpd);
  1825. /* TV - TV DAC */
  1826. ddc_i2c.valid = false;
  1827. hpd.hpd = RADEON_HPD_NONE;
  1828. radeon_add_legacy_encoder(dev,
  1829. radeon_get_encoder_enum(dev,
  1830. ATOM_DEVICE_TV1_SUPPORT,
  1831. 2),
  1832. ATOM_DEVICE_TV1_SUPPORT);
  1833. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1834. DRM_MODE_CONNECTOR_SVIDEO,
  1835. &ddc_i2c,
  1836. CONNECTOR_OBJECT_ID_SVIDEO,
  1837. &hpd);
  1838. break;
  1839. case CT_EMAC:
  1840. DRM_INFO("Connector Table: %d (emac)\n",
  1841. rdev->mode_info.connector_table);
  1842. /* VGA - primary dac */
  1843. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1844. hpd.hpd = RADEON_HPD_NONE;
  1845. radeon_add_legacy_encoder(dev,
  1846. radeon_get_encoder_enum(dev,
  1847. ATOM_DEVICE_CRT1_SUPPORT,
  1848. 1),
  1849. ATOM_DEVICE_CRT1_SUPPORT);
  1850. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1851. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1852. CONNECTOR_OBJECT_ID_VGA,
  1853. &hpd);
  1854. /* VGA - tv dac */
  1855. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1856. hpd.hpd = RADEON_HPD_NONE;
  1857. radeon_add_legacy_encoder(dev,
  1858. radeon_get_encoder_enum(dev,
  1859. ATOM_DEVICE_CRT2_SUPPORT,
  1860. 2),
  1861. ATOM_DEVICE_CRT2_SUPPORT);
  1862. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1863. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1864. CONNECTOR_OBJECT_ID_VGA,
  1865. &hpd);
  1866. /* TV - TV DAC */
  1867. ddc_i2c.valid = false;
  1868. hpd.hpd = RADEON_HPD_NONE;
  1869. radeon_add_legacy_encoder(dev,
  1870. radeon_get_encoder_enum(dev,
  1871. ATOM_DEVICE_TV1_SUPPORT,
  1872. 2),
  1873. ATOM_DEVICE_TV1_SUPPORT);
  1874. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1875. DRM_MODE_CONNECTOR_SVIDEO,
  1876. &ddc_i2c,
  1877. CONNECTOR_OBJECT_ID_SVIDEO,
  1878. &hpd);
  1879. break;
  1880. case CT_RN50_POWER:
  1881. DRM_INFO("Connector Table: %d (rn50-power)\n",
  1882. rdev->mode_info.connector_table);
  1883. /* VGA - primary dac */
  1884. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1885. hpd.hpd = RADEON_HPD_NONE;
  1886. radeon_add_legacy_encoder(dev,
  1887. radeon_get_encoder_enum(dev,
  1888. ATOM_DEVICE_CRT1_SUPPORT,
  1889. 1),
  1890. ATOM_DEVICE_CRT1_SUPPORT);
  1891. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1892. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1893. CONNECTOR_OBJECT_ID_VGA,
  1894. &hpd);
  1895. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1896. hpd.hpd = RADEON_HPD_NONE;
  1897. radeon_add_legacy_encoder(dev,
  1898. radeon_get_encoder_enum(dev,
  1899. ATOM_DEVICE_CRT2_SUPPORT,
  1900. 2),
  1901. ATOM_DEVICE_CRT2_SUPPORT);
  1902. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1903. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1904. CONNECTOR_OBJECT_ID_VGA,
  1905. &hpd);
  1906. break;
  1907. case CT_MAC_X800:
  1908. DRM_INFO("Connector Table: %d (mac x800)\n",
  1909. rdev->mode_info.connector_table);
  1910. /* DVI - primary dac, internal tmds */
  1911. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1912. hpd.hpd = RADEON_HPD_1; /* ??? */
  1913. radeon_add_legacy_encoder(dev,
  1914. radeon_get_encoder_enum(dev,
  1915. ATOM_DEVICE_DFP1_SUPPORT,
  1916. 0),
  1917. ATOM_DEVICE_DFP1_SUPPORT);
  1918. radeon_add_legacy_encoder(dev,
  1919. radeon_get_encoder_enum(dev,
  1920. ATOM_DEVICE_CRT1_SUPPORT,
  1921. 1),
  1922. ATOM_DEVICE_CRT1_SUPPORT);
  1923. radeon_add_legacy_connector(dev, 0,
  1924. ATOM_DEVICE_DFP1_SUPPORT |
  1925. ATOM_DEVICE_CRT1_SUPPORT,
  1926. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1927. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1928. &hpd);
  1929. /* DVI - tv dac, dvo */
  1930. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1931. hpd.hpd = RADEON_HPD_2; /* ??? */
  1932. radeon_add_legacy_encoder(dev,
  1933. radeon_get_encoder_enum(dev,
  1934. ATOM_DEVICE_DFP2_SUPPORT,
  1935. 0),
  1936. ATOM_DEVICE_DFP2_SUPPORT);
  1937. radeon_add_legacy_encoder(dev,
  1938. radeon_get_encoder_enum(dev,
  1939. ATOM_DEVICE_CRT2_SUPPORT,
  1940. 2),
  1941. ATOM_DEVICE_CRT2_SUPPORT);
  1942. radeon_add_legacy_connector(dev, 1,
  1943. ATOM_DEVICE_DFP2_SUPPORT |
  1944. ATOM_DEVICE_CRT2_SUPPORT,
  1945. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1946. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1947. &hpd);
  1948. break;
  1949. case CT_MAC_G5_9600:
  1950. DRM_INFO("Connector Table: %d (mac g5 9600)\n",
  1951. rdev->mode_info.connector_table);
  1952. /* DVI - tv dac, dvo */
  1953. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1954. hpd.hpd = RADEON_HPD_1; /* ??? */
  1955. radeon_add_legacy_encoder(dev,
  1956. radeon_get_encoder_enum(dev,
  1957. ATOM_DEVICE_DFP2_SUPPORT,
  1958. 0),
  1959. ATOM_DEVICE_DFP2_SUPPORT);
  1960. radeon_add_legacy_encoder(dev,
  1961. radeon_get_encoder_enum(dev,
  1962. ATOM_DEVICE_CRT2_SUPPORT,
  1963. 2),
  1964. ATOM_DEVICE_CRT2_SUPPORT);
  1965. radeon_add_legacy_connector(dev, 0,
  1966. ATOM_DEVICE_DFP2_SUPPORT |
  1967. ATOM_DEVICE_CRT2_SUPPORT,
  1968. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1969. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1970. &hpd);
  1971. /* ADC - primary dac, internal tmds */
  1972. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1973. hpd.hpd = RADEON_HPD_2; /* ??? */
  1974. radeon_add_legacy_encoder(dev,
  1975. radeon_get_encoder_enum(dev,
  1976. ATOM_DEVICE_DFP1_SUPPORT,
  1977. 0),
  1978. ATOM_DEVICE_DFP1_SUPPORT);
  1979. radeon_add_legacy_encoder(dev,
  1980. radeon_get_encoder_enum(dev,
  1981. ATOM_DEVICE_CRT1_SUPPORT,
  1982. 1),
  1983. ATOM_DEVICE_CRT1_SUPPORT);
  1984. radeon_add_legacy_connector(dev, 1,
  1985. ATOM_DEVICE_DFP1_SUPPORT |
  1986. ATOM_DEVICE_CRT1_SUPPORT,
  1987. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1988. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1989. &hpd);
  1990. /* TV - TV DAC */
  1991. ddc_i2c.valid = false;
  1992. hpd.hpd = RADEON_HPD_NONE;
  1993. radeon_add_legacy_encoder(dev,
  1994. radeon_get_encoder_enum(dev,
  1995. ATOM_DEVICE_TV1_SUPPORT,
  1996. 2),
  1997. ATOM_DEVICE_TV1_SUPPORT);
  1998. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1999. DRM_MODE_CONNECTOR_SVIDEO,
  2000. &ddc_i2c,
  2001. CONNECTOR_OBJECT_ID_SVIDEO,
  2002. &hpd);
  2003. break;
  2004. default:
  2005. DRM_INFO("Connector table: %d (invalid)\n",
  2006. rdev->mode_info.connector_table);
  2007. return false;
  2008. }
  2009. radeon_link_encoder_connector(dev);
  2010. return true;
  2011. }
  2012. static bool radeon_apply_legacy_quirks(struct drm_device *dev,
  2013. int bios_index,
  2014. enum radeon_combios_connector
  2015. *legacy_connector,
  2016. struct radeon_i2c_bus_rec *ddc_i2c,
  2017. struct radeon_hpd *hpd)
  2018. {
  2019. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  2020. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  2021. if (dev->pdev->device == 0x515e &&
  2022. dev->pdev->subsystem_vendor == 0x1014) {
  2023. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  2024. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  2025. return false;
  2026. }
  2027. /* X300 card with extra non-existent DVI port */
  2028. if (dev->pdev->device == 0x5B60 &&
  2029. dev->pdev->subsystem_vendor == 0x17af &&
  2030. dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  2031. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  2032. return false;
  2033. }
  2034. return true;
  2035. }
  2036. static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
  2037. {
  2038. /* Acer 5102 has non-existent TV port */
  2039. if (dev->pdev->device == 0x5975 &&
  2040. dev->pdev->subsystem_vendor == 0x1025 &&
  2041. dev->pdev->subsystem_device == 0x009f)
  2042. return false;
  2043. /* HP dc5750 has non-existent TV port */
  2044. if (dev->pdev->device == 0x5974 &&
  2045. dev->pdev->subsystem_vendor == 0x103c &&
  2046. dev->pdev->subsystem_device == 0x280a)
  2047. return false;
  2048. /* MSI S270 has non-existent TV port */
  2049. if (dev->pdev->device == 0x5955 &&
  2050. dev->pdev->subsystem_vendor == 0x1462 &&
  2051. dev->pdev->subsystem_device == 0x0131)
  2052. return false;
  2053. return true;
  2054. }
  2055. static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
  2056. {
  2057. struct radeon_device *rdev = dev->dev_private;
  2058. uint32_t ext_tmds_info;
  2059. if (rdev->flags & RADEON_IS_IGP) {
  2060. if (is_dvi_d)
  2061. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2062. else
  2063. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2064. }
  2065. ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2066. if (ext_tmds_info) {
  2067. uint8_t rev = RBIOS8(ext_tmds_info);
  2068. uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
  2069. if (rev >= 3) {
  2070. if (is_dvi_d)
  2071. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2072. else
  2073. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2074. } else {
  2075. if (flags & 1) {
  2076. if (is_dvi_d)
  2077. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2078. else
  2079. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2080. }
  2081. }
  2082. }
  2083. if (is_dvi_d)
  2084. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2085. else
  2086. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2087. }
  2088. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  2089. {
  2090. struct radeon_device *rdev = dev->dev_private;
  2091. uint32_t conn_info, entry, devices;
  2092. uint16_t tmp, connector_object_id;
  2093. enum radeon_combios_ddc ddc_type;
  2094. enum radeon_combios_connector connector;
  2095. int i = 0;
  2096. struct radeon_i2c_bus_rec ddc_i2c;
  2097. struct radeon_hpd hpd;
  2098. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  2099. if (conn_info) {
  2100. for (i = 0; i < 4; i++) {
  2101. entry = conn_info + 2 + i * 2;
  2102. if (!RBIOS16(entry))
  2103. break;
  2104. tmp = RBIOS16(entry);
  2105. connector = (tmp >> 12) & 0xf;
  2106. ddc_type = (tmp >> 8) & 0xf;
  2107. ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2108. switch (connector) {
  2109. case CONNECTOR_PROPRIETARY_LEGACY:
  2110. case CONNECTOR_DVI_I_LEGACY:
  2111. case CONNECTOR_DVI_D_LEGACY:
  2112. if ((tmp >> 4) & 0x1)
  2113. hpd.hpd = RADEON_HPD_2;
  2114. else
  2115. hpd.hpd = RADEON_HPD_1;
  2116. break;
  2117. default:
  2118. hpd.hpd = RADEON_HPD_NONE;
  2119. break;
  2120. }
  2121. if (!radeon_apply_legacy_quirks(dev, i, &connector,
  2122. &ddc_i2c, &hpd))
  2123. continue;
  2124. switch (connector) {
  2125. case CONNECTOR_PROPRIETARY_LEGACY:
  2126. if ((tmp >> 4) & 0x1)
  2127. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2128. else
  2129. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2130. radeon_add_legacy_encoder(dev,
  2131. radeon_get_encoder_enum
  2132. (dev, devices, 0),
  2133. devices);
  2134. radeon_add_legacy_connector(dev, i, devices,
  2135. legacy_connector_convert
  2136. [connector],
  2137. &ddc_i2c,
  2138. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  2139. &hpd);
  2140. break;
  2141. case CONNECTOR_CRT_LEGACY:
  2142. if (tmp & 0x1) {
  2143. devices = ATOM_DEVICE_CRT2_SUPPORT;
  2144. radeon_add_legacy_encoder(dev,
  2145. radeon_get_encoder_enum
  2146. (dev,
  2147. ATOM_DEVICE_CRT2_SUPPORT,
  2148. 2),
  2149. ATOM_DEVICE_CRT2_SUPPORT);
  2150. } else {
  2151. devices = ATOM_DEVICE_CRT1_SUPPORT;
  2152. radeon_add_legacy_encoder(dev,
  2153. radeon_get_encoder_enum
  2154. (dev,
  2155. ATOM_DEVICE_CRT1_SUPPORT,
  2156. 1),
  2157. ATOM_DEVICE_CRT1_SUPPORT);
  2158. }
  2159. radeon_add_legacy_connector(dev,
  2160. i,
  2161. devices,
  2162. legacy_connector_convert
  2163. [connector],
  2164. &ddc_i2c,
  2165. CONNECTOR_OBJECT_ID_VGA,
  2166. &hpd);
  2167. break;
  2168. case CONNECTOR_DVI_I_LEGACY:
  2169. devices = 0;
  2170. if (tmp & 0x1) {
  2171. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  2172. radeon_add_legacy_encoder(dev,
  2173. radeon_get_encoder_enum
  2174. (dev,
  2175. ATOM_DEVICE_CRT2_SUPPORT,
  2176. 2),
  2177. ATOM_DEVICE_CRT2_SUPPORT);
  2178. } else {
  2179. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  2180. radeon_add_legacy_encoder(dev,
  2181. radeon_get_encoder_enum
  2182. (dev,
  2183. ATOM_DEVICE_CRT1_SUPPORT,
  2184. 1),
  2185. ATOM_DEVICE_CRT1_SUPPORT);
  2186. }
  2187. if ((tmp >> 4) & 0x1) {
  2188. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  2189. radeon_add_legacy_encoder(dev,
  2190. radeon_get_encoder_enum
  2191. (dev,
  2192. ATOM_DEVICE_DFP2_SUPPORT,
  2193. 0),
  2194. ATOM_DEVICE_DFP2_SUPPORT);
  2195. connector_object_id = combios_check_dl_dvi(dev, 0);
  2196. } else {
  2197. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  2198. radeon_add_legacy_encoder(dev,
  2199. radeon_get_encoder_enum
  2200. (dev,
  2201. ATOM_DEVICE_DFP1_SUPPORT,
  2202. 0),
  2203. ATOM_DEVICE_DFP1_SUPPORT);
  2204. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2205. }
  2206. radeon_add_legacy_connector(dev,
  2207. i,
  2208. devices,
  2209. legacy_connector_convert
  2210. [connector],
  2211. &ddc_i2c,
  2212. connector_object_id,
  2213. &hpd);
  2214. break;
  2215. case CONNECTOR_DVI_D_LEGACY:
  2216. if ((tmp >> 4) & 0x1) {
  2217. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2218. connector_object_id = combios_check_dl_dvi(dev, 1);
  2219. } else {
  2220. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2221. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2222. }
  2223. radeon_add_legacy_encoder(dev,
  2224. radeon_get_encoder_enum
  2225. (dev, devices, 0),
  2226. devices);
  2227. radeon_add_legacy_connector(dev, i, devices,
  2228. legacy_connector_convert
  2229. [connector],
  2230. &ddc_i2c,
  2231. connector_object_id,
  2232. &hpd);
  2233. break;
  2234. case CONNECTOR_CTV_LEGACY:
  2235. case CONNECTOR_STV_LEGACY:
  2236. radeon_add_legacy_encoder(dev,
  2237. radeon_get_encoder_enum
  2238. (dev,
  2239. ATOM_DEVICE_TV1_SUPPORT,
  2240. 2),
  2241. ATOM_DEVICE_TV1_SUPPORT);
  2242. radeon_add_legacy_connector(dev, i,
  2243. ATOM_DEVICE_TV1_SUPPORT,
  2244. legacy_connector_convert
  2245. [connector],
  2246. &ddc_i2c,
  2247. CONNECTOR_OBJECT_ID_SVIDEO,
  2248. &hpd);
  2249. break;
  2250. default:
  2251. DRM_ERROR("Unknown connector type: %d\n",
  2252. connector);
  2253. continue;
  2254. }
  2255. }
  2256. } else {
  2257. uint16_t tmds_info =
  2258. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  2259. if (tmds_info) {
  2260. DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
  2261. radeon_add_legacy_encoder(dev,
  2262. radeon_get_encoder_enum(dev,
  2263. ATOM_DEVICE_CRT1_SUPPORT,
  2264. 1),
  2265. ATOM_DEVICE_CRT1_SUPPORT);
  2266. radeon_add_legacy_encoder(dev,
  2267. radeon_get_encoder_enum(dev,
  2268. ATOM_DEVICE_DFP1_SUPPORT,
  2269. 0),
  2270. ATOM_DEVICE_DFP1_SUPPORT);
  2271. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  2272. hpd.hpd = RADEON_HPD_1;
  2273. radeon_add_legacy_connector(dev,
  2274. 0,
  2275. ATOM_DEVICE_CRT1_SUPPORT |
  2276. ATOM_DEVICE_DFP1_SUPPORT,
  2277. DRM_MODE_CONNECTOR_DVII,
  2278. &ddc_i2c,
  2279. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2280. &hpd);
  2281. } else {
  2282. uint16_t crt_info =
  2283. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  2284. DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
  2285. if (crt_info) {
  2286. radeon_add_legacy_encoder(dev,
  2287. radeon_get_encoder_enum(dev,
  2288. ATOM_DEVICE_CRT1_SUPPORT,
  2289. 1),
  2290. ATOM_DEVICE_CRT1_SUPPORT);
  2291. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  2292. hpd.hpd = RADEON_HPD_NONE;
  2293. radeon_add_legacy_connector(dev,
  2294. 0,
  2295. ATOM_DEVICE_CRT1_SUPPORT,
  2296. DRM_MODE_CONNECTOR_VGA,
  2297. &ddc_i2c,
  2298. CONNECTOR_OBJECT_ID_VGA,
  2299. &hpd);
  2300. } else {
  2301. DRM_DEBUG_KMS("No connector info found\n");
  2302. return false;
  2303. }
  2304. }
  2305. }
  2306. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  2307. uint16_t lcd_info =
  2308. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  2309. if (lcd_info) {
  2310. uint16_t lcd_ddc_info =
  2311. combios_get_table_offset(dev,
  2312. COMBIOS_LCD_DDC_INFO_TABLE);
  2313. radeon_add_legacy_encoder(dev,
  2314. radeon_get_encoder_enum(dev,
  2315. ATOM_DEVICE_LCD1_SUPPORT,
  2316. 0),
  2317. ATOM_DEVICE_LCD1_SUPPORT);
  2318. if (lcd_ddc_info) {
  2319. ddc_type = RBIOS8(lcd_ddc_info + 2);
  2320. switch (ddc_type) {
  2321. case DDC_LCD:
  2322. ddc_i2c =
  2323. combios_setup_i2c_bus(rdev,
  2324. DDC_LCD,
  2325. RBIOS32(lcd_ddc_info + 3),
  2326. RBIOS32(lcd_ddc_info + 7));
  2327. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2328. break;
  2329. case DDC_GPIO:
  2330. ddc_i2c =
  2331. combios_setup_i2c_bus(rdev,
  2332. DDC_GPIO,
  2333. RBIOS32(lcd_ddc_info + 3),
  2334. RBIOS32(lcd_ddc_info + 7));
  2335. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2336. break;
  2337. default:
  2338. ddc_i2c =
  2339. combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2340. break;
  2341. }
  2342. DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
  2343. } else
  2344. ddc_i2c.valid = false;
  2345. hpd.hpd = RADEON_HPD_NONE;
  2346. radeon_add_legacy_connector(dev,
  2347. 5,
  2348. ATOM_DEVICE_LCD1_SUPPORT,
  2349. DRM_MODE_CONNECTOR_LVDS,
  2350. &ddc_i2c,
  2351. CONNECTOR_OBJECT_ID_LVDS,
  2352. &hpd);
  2353. }
  2354. }
  2355. /* check TV table */
  2356. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  2357. uint32_t tv_info =
  2358. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  2359. if (tv_info) {
  2360. if (RBIOS8(tv_info + 6) == 'T') {
  2361. if (radeon_apply_legacy_tv_quirks(dev)) {
  2362. hpd.hpd = RADEON_HPD_NONE;
  2363. ddc_i2c.valid = false;
  2364. radeon_add_legacy_encoder(dev,
  2365. radeon_get_encoder_enum
  2366. (dev,
  2367. ATOM_DEVICE_TV1_SUPPORT,
  2368. 2),
  2369. ATOM_DEVICE_TV1_SUPPORT);
  2370. radeon_add_legacy_connector(dev, 6,
  2371. ATOM_DEVICE_TV1_SUPPORT,
  2372. DRM_MODE_CONNECTOR_SVIDEO,
  2373. &ddc_i2c,
  2374. CONNECTOR_OBJECT_ID_SVIDEO,
  2375. &hpd);
  2376. }
  2377. }
  2378. }
  2379. }
  2380. radeon_link_encoder_connector(dev);
  2381. return true;
  2382. }
  2383. static const char *thermal_controller_names[] = {
  2384. "NONE",
  2385. "lm63",
  2386. "adm1032",
  2387. };
  2388. void radeon_combios_get_power_modes(struct radeon_device *rdev)
  2389. {
  2390. struct drm_device *dev = rdev->ddev;
  2391. u16 offset, misc, misc2 = 0;
  2392. u8 rev, blocks, tmp;
  2393. int state_index = 0;
  2394. struct radeon_i2c_bus_rec i2c_bus;
  2395. rdev->pm.default_power_state_index = -1;
  2396. /* allocate 2 power states */
  2397. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
  2398. if (rdev->pm.power_state) {
  2399. /* allocate 1 clock mode per state */
  2400. rdev->pm.power_state[0].clock_info =
  2401. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2402. rdev->pm.power_state[1].clock_info =
  2403. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2404. if (!rdev->pm.power_state[0].clock_info ||
  2405. !rdev->pm.power_state[1].clock_info)
  2406. goto pm_failed;
  2407. } else
  2408. goto pm_failed;
  2409. /* check for a thermal chip */
  2410. offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
  2411. if (offset) {
  2412. u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
  2413. rev = RBIOS8(offset);
  2414. if (rev == 0) {
  2415. thermal_controller = RBIOS8(offset + 3);
  2416. gpio = RBIOS8(offset + 4) & 0x3f;
  2417. i2c_addr = RBIOS8(offset + 5);
  2418. } else if (rev == 1) {
  2419. thermal_controller = RBIOS8(offset + 4);
  2420. gpio = RBIOS8(offset + 5) & 0x3f;
  2421. i2c_addr = RBIOS8(offset + 6);
  2422. } else if (rev == 2) {
  2423. thermal_controller = RBIOS8(offset + 4);
  2424. gpio = RBIOS8(offset + 5) & 0x3f;
  2425. i2c_addr = RBIOS8(offset + 6);
  2426. clk_bit = RBIOS8(offset + 0xa);
  2427. data_bit = RBIOS8(offset + 0xb);
  2428. }
  2429. if ((thermal_controller > 0) && (thermal_controller < 3)) {
  2430. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2431. thermal_controller_names[thermal_controller],
  2432. i2c_addr >> 1);
  2433. if (gpio == DDC_LCD) {
  2434. /* MM i2c */
  2435. i2c_bus.valid = true;
  2436. i2c_bus.hw_capable = true;
  2437. i2c_bus.mm_i2c = true;
  2438. i2c_bus.i2c_id = 0xa0;
  2439. } else if (gpio == DDC_GPIO)
  2440. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
  2441. else
  2442. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  2443. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2444. if (rdev->pm.i2c_bus) {
  2445. struct i2c_board_info info = { };
  2446. const char *name = thermal_controller_names[thermal_controller];
  2447. info.addr = i2c_addr >> 1;
  2448. strlcpy(info.type, name, sizeof(info.type));
  2449. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2450. }
  2451. }
  2452. } else {
  2453. /* boards with a thermal chip, but no overdrive table */
  2454. /* Asus 9600xt has an f75375 on the monid bus */
  2455. if ((dev->pdev->device == 0x4152) &&
  2456. (dev->pdev->subsystem_vendor == 0x1043) &&
  2457. (dev->pdev->subsystem_device == 0xc002)) {
  2458. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  2459. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2460. if (rdev->pm.i2c_bus) {
  2461. struct i2c_board_info info = { };
  2462. const char *name = "f75375";
  2463. info.addr = 0x28;
  2464. strlcpy(info.type, name, sizeof(info.type));
  2465. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2466. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2467. name, info.addr);
  2468. }
  2469. }
  2470. }
  2471. if (rdev->flags & RADEON_IS_MOBILITY) {
  2472. offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
  2473. if (offset) {
  2474. rev = RBIOS8(offset);
  2475. blocks = RBIOS8(offset + 0x2);
  2476. /* power mode 0 tends to be the only valid one */
  2477. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2478. rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
  2479. rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
  2480. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  2481. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  2482. goto default_mode;
  2483. rdev->pm.power_state[state_index].type =
  2484. POWER_STATE_TYPE_BATTERY;
  2485. misc = RBIOS16(offset + 0x5 + 0x0);
  2486. if (rev > 4)
  2487. misc2 = RBIOS16(offset + 0x5 + 0xe);
  2488. rdev->pm.power_state[state_index].misc = misc;
  2489. rdev->pm.power_state[state_index].misc2 = misc2;
  2490. if (misc & 0x4) {
  2491. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
  2492. if (misc & 0x8)
  2493. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2494. true;
  2495. else
  2496. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2497. false;
  2498. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
  2499. if (rev < 6) {
  2500. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2501. RBIOS16(offset + 0x5 + 0xb) * 4;
  2502. tmp = RBIOS8(offset + 0x5 + 0xd);
  2503. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2504. } else {
  2505. u8 entries = RBIOS8(offset + 0x5 + 0xb);
  2506. u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
  2507. if (entries && voltage_table_offset) {
  2508. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2509. RBIOS16(voltage_table_offset) * 4;
  2510. tmp = RBIOS8(voltage_table_offset + 0x2);
  2511. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2512. } else
  2513. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
  2514. }
  2515. switch ((misc2 & 0x700) >> 8) {
  2516. case 0:
  2517. default:
  2518. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
  2519. break;
  2520. case 1:
  2521. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
  2522. break;
  2523. case 2:
  2524. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
  2525. break;
  2526. case 3:
  2527. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
  2528. break;
  2529. case 4:
  2530. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
  2531. break;
  2532. }
  2533. } else
  2534. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2535. if (rev > 6)
  2536. rdev->pm.power_state[state_index].pcie_lanes =
  2537. RBIOS8(offset + 0x5 + 0x10);
  2538. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2539. state_index++;
  2540. } else {
  2541. /* XXX figure out some good default low power mode for mobility cards w/out power tables */
  2542. }
  2543. } else {
  2544. /* XXX figure out some good default low power mode for desktop cards */
  2545. }
  2546. default_mode:
  2547. /* add the default mode */
  2548. rdev->pm.power_state[state_index].type =
  2549. POWER_STATE_TYPE_DEFAULT;
  2550. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2551. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2552. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2553. rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
  2554. if ((state_index > 0) &&
  2555. (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
  2556. rdev->pm.power_state[state_index].clock_info[0].voltage =
  2557. rdev->pm.power_state[0].clock_info[0].voltage;
  2558. else
  2559. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2560. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2561. rdev->pm.power_state[state_index].flags = 0;
  2562. rdev->pm.default_power_state_index = state_index;
  2563. rdev->pm.num_power_states = state_index + 1;
  2564. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2565. rdev->pm.current_clock_mode_index = 0;
  2566. return;
  2567. pm_failed:
  2568. rdev->pm.default_power_state_index = state_index;
  2569. rdev->pm.num_power_states = 0;
  2570. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2571. rdev->pm.current_clock_mode_index = 0;
  2572. }
  2573. void radeon_external_tmds_setup(struct drm_encoder *encoder)
  2574. {
  2575. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2576. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2577. if (!tmds)
  2578. return;
  2579. switch (tmds->dvo_chip) {
  2580. case DVO_SIL164:
  2581. /* sil 164 */
  2582. radeon_i2c_put_byte(tmds->i2c_bus,
  2583. tmds->slave_addr,
  2584. 0x08, 0x30);
  2585. radeon_i2c_put_byte(tmds->i2c_bus,
  2586. tmds->slave_addr,
  2587. 0x09, 0x00);
  2588. radeon_i2c_put_byte(tmds->i2c_bus,
  2589. tmds->slave_addr,
  2590. 0x0a, 0x90);
  2591. radeon_i2c_put_byte(tmds->i2c_bus,
  2592. tmds->slave_addr,
  2593. 0x0c, 0x89);
  2594. radeon_i2c_put_byte(tmds->i2c_bus,
  2595. tmds->slave_addr,
  2596. 0x08, 0x3b);
  2597. break;
  2598. case DVO_SIL1178:
  2599. /* sil 1178 - untested */
  2600. /*
  2601. * 0x0f, 0x44
  2602. * 0x0f, 0x4c
  2603. * 0x0e, 0x01
  2604. * 0x0a, 0x80
  2605. * 0x09, 0x30
  2606. * 0x0c, 0xc9
  2607. * 0x0d, 0x70
  2608. * 0x08, 0x32
  2609. * 0x08, 0x33
  2610. */
  2611. break;
  2612. default:
  2613. break;
  2614. }
  2615. }
  2616. bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
  2617. {
  2618. struct drm_device *dev = encoder->dev;
  2619. struct radeon_device *rdev = dev->dev_private;
  2620. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2621. uint16_t offset;
  2622. uint8_t blocks, slave_addr, rev;
  2623. uint32_t index, id;
  2624. uint32_t reg, val, and_mask, or_mask;
  2625. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2626. if (!tmds)
  2627. return false;
  2628. if (rdev->flags & RADEON_IS_IGP) {
  2629. offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
  2630. rev = RBIOS8(offset);
  2631. if (offset) {
  2632. rev = RBIOS8(offset);
  2633. if (rev > 1) {
  2634. blocks = RBIOS8(offset + 3);
  2635. index = offset + 4;
  2636. while (blocks > 0) {
  2637. id = RBIOS16(index);
  2638. index += 2;
  2639. switch (id >> 13) {
  2640. case 0:
  2641. reg = (id & 0x1fff) * 4;
  2642. val = RBIOS32(index);
  2643. index += 4;
  2644. WREG32(reg, val);
  2645. break;
  2646. case 2:
  2647. reg = (id & 0x1fff) * 4;
  2648. and_mask = RBIOS32(index);
  2649. index += 4;
  2650. or_mask = RBIOS32(index);
  2651. index += 4;
  2652. val = RREG32(reg);
  2653. val = (val & and_mask) | or_mask;
  2654. WREG32(reg, val);
  2655. break;
  2656. case 3:
  2657. val = RBIOS16(index);
  2658. index += 2;
  2659. udelay(val);
  2660. break;
  2661. case 4:
  2662. val = RBIOS16(index);
  2663. index += 2;
  2664. udelay(val * 1000);
  2665. break;
  2666. case 6:
  2667. slave_addr = id & 0xff;
  2668. slave_addr >>= 1; /* 7 bit addressing */
  2669. index++;
  2670. reg = RBIOS8(index);
  2671. index++;
  2672. val = RBIOS8(index);
  2673. index++;
  2674. radeon_i2c_put_byte(tmds->i2c_bus,
  2675. slave_addr,
  2676. reg, val);
  2677. break;
  2678. default:
  2679. DRM_ERROR("Unknown id %d\n", id >> 13);
  2680. break;
  2681. }
  2682. blocks--;
  2683. }
  2684. return true;
  2685. }
  2686. }
  2687. } else {
  2688. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2689. if (offset) {
  2690. index = offset + 10;
  2691. id = RBIOS16(index);
  2692. while (id != 0xffff) {
  2693. index += 2;
  2694. switch (id >> 13) {
  2695. case 0:
  2696. reg = (id & 0x1fff) * 4;
  2697. val = RBIOS32(index);
  2698. WREG32(reg, val);
  2699. break;
  2700. case 2:
  2701. reg = (id & 0x1fff) * 4;
  2702. and_mask = RBIOS32(index);
  2703. index += 4;
  2704. or_mask = RBIOS32(index);
  2705. index += 4;
  2706. val = RREG32(reg);
  2707. val = (val & and_mask) | or_mask;
  2708. WREG32(reg, val);
  2709. break;
  2710. case 4:
  2711. val = RBIOS16(index);
  2712. index += 2;
  2713. udelay(val);
  2714. break;
  2715. case 5:
  2716. reg = id & 0x1fff;
  2717. and_mask = RBIOS32(index);
  2718. index += 4;
  2719. or_mask = RBIOS32(index);
  2720. index += 4;
  2721. val = RREG32_PLL(reg);
  2722. val = (val & and_mask) | or_mask;
  2723. WREG32_PLL(reg, val);
  2724. break;
  2725. case 6:
  2726. reg = id & 0x1fff;
  2727. val = RBIOS8(index);
  2728. index += 1;
  2729. radeon_i2c_put_byte(tmds->i2c_bus,
  2730. tmds->slave_addr,
  2731. reg, val);
  2732. break;
  2733. default:
  2734. DRM_ERROR("Unknown id %d\n", id >> 13);
  2735. break;
  2736. }
  2737. id = RBIOS16(index);
  2738. }
  2739. return true;
  2740. }
  2741. }
  2742. return false;
  2743. }
  2744. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  2745. {
  2746. struct radeon_device *rdev = dev->dev_private;
  2747. if (offset) {
  2748. while (RBIOS16(offset)) {
  2749. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  2750. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  2751. uint32_t val, and_mask, or_mask;
  2752. uint32_t tmp;
  2753. offset += 2;
  2754. switch (cmd) {
  2755. case 0:
  2756. val = RBIOS32(offset);
  2757. offset += 4;
  2758. WREG32(addr, val);
  2759. break;
  2760. case 1:
  2761. val = RBIOS32(offset);
  2762. offset += 4;
  2763. WREG32(addr, val);
  2764. break;
  2765. case 2:
  2766. and_mask = RBIOS32(offset);
  2767. offset += 4;
  2768. or_mask = RBIOS32(offset);
  2769. offset += 4;
  2770. tmp = RREG32(addr);
  2771. tmp &= and_mask;
  2772. tmp |= or_mask;
  2773. WREG32(addr, tmp);
  2774. break;
  2775. case 3:
  2776. and_mask = RBIOS32(offset);
  2777. offset += 4;
  2778. or_mask = RBIOS32(offset);
  2779. offset += 4;
  2780. tmp = RREG32(addr);
  2781. tmp &= and_mask;
  2782. tmp |= or_mask;
  2783. WREG32(addr, tmp);
  2784. break;
  2785. case 4:
  2786. val = RBIOS16(offset);
  2787. offset += 2;
  2788. udelay(val);
  2789. break;
  2790. case 5:
  2791. val = RBIOS16(offset);
  2792. offset += 2;
  2793. switch (addr) {
  2794. case 8:
  2795. while (val--) {
  2796. if (!
  2797. (RREG32_PLL
  2798. (RADEON_CLK_PWRMGT_CNTL) &
  2799. RADEON_MC_BUSY))
  2800. break;
  2801. }
  2802. break;
  2803. case 9:
  2804. while (val--) {
  2805. if ((RREG32(RADEON_MC_STATUS) &
  2806. RADEON_MC_IDLE))
  2807. break;
  2808. }
  2809. break;
  2810. default:
  2811. break;
  2812. }
  2813. break;
  2814. default:
  2815. break;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  2821. {
  2822. struct radeon_device *rdev = dev->dev_private;
  2823. if (offset) {
  2824. while (RBIOS8(offset)) {
  2825. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  2826. uint8_t addr = (RBIOS8(offset) & 0x3f);
  2827. uint32_t val, shift, tmp;
  2828. uint32_t and_mask, or_mask;
  2829. offset++;
  2830. switch (cmd) {
  2831. case 0:
  2832. val = RBIOS32(offset);
  2833. offset += 4;
  2834. WREG32_PLL(addr, val);
  2835. break;
  2836. case 1:
  2837. shift = RBIOS8(offset) * 8;
  2838. offset++;
  2839. and_mask = RBIOS8(offset) << shift;
  2840. and_mask |= ~(0xff << shift);
  2841. offset++;
  2842. or_mask = RBIOS8(offset) << shift;
  2843. offset++;
  2844. tmp = RREG32_PLL(addr);
  2845. tmp &= and_mask;
  2846. tmp |= or_mask;
  2847. WREG32_PLL(addr, tmp);
  2848. break;
  2849. case 2:
  2850. case 3:
  2851. tmp = 1000;
  2852. switch (addr) {
  2853. case 1:
  2854. udelay(150);
  2855. break;
  2856. case 2:
  2857. udelay(1000);
  2858. break;
  2859. case 3:
  2860. while (tmp--) {
  2861. if (!
  2862. (RREG32_PLL
  2863. (RADEON_CLK_PWRMGT_CNTL) &
  2864. RADEON_MC_BUSY))
  2865. break;
  2866. }
  2867. break;
  2868. case 4:
  2869. while (tmp--) {
  2870. if (RREG32_PLL
  2871. (RADEON_CLK_PWRMGT_CNTL) &
  2872. RADEON_DLL_READY)
  2873. break;
  2874. }
  2875. break;
  2876. case 5:
  2877. tmp =
  2878. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  2879. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  2880. #if 0
  2881. uint32_t mclk_cntl =
  2882. RREG32_PLL
  2883. (RADEON_MCLK_CNTL);
  2884. mclk_cntl &= 0xffff0000;
  2885. /*mclk_cntl |= 0x00001111;*//* ??? */
  2886. WREG32_PLL(RADEON_MCLK_CNTL,
  2887. mclk_cntl);
  2888. udelay(10000);
  2889. #endif
  2890. WREG32_PLL
  2891. (RADEON_CLK_PWRMGT_CNTL,
  2892. tmp &
  2893. ~RADEON_CG_NO1_DEBUG_0);
  2894. udelay(10000);
  2895. }
  2896. break;
  2897. default:
  2898. break;
  2899. }
  2900. break;
  2901. default:
  2902. break;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. static void combios_parse_ram_reset_table(struct drm_device *dev,
  2908. uint16_t offset)
  2909. {
  2910. struct radeon_device *rdev = dev->dev_private;
  2911. uint32_t tmp;
  2912. if (offset) {
  2913. uint8_t val = RBIOS8(offset);
  2914. while (val != 0xff) {
  2915. offset++;
  2916. if (val == 0x0f) {
  2917. uint32_t channel_complete_mask;
  2918. if (ASIC_IS_R300(rdev))
  2919. channel_complete_mask =
  2920. R300_MEM_PWRUP_COMPLETE;
  2921. else
  2922. channel_complete_mask =
  2923. RADEON_MEM_PWRUP_COMPLETE;
  2924. tmp = 20000;
  2925. while (tmp--) {
  2926. if ((RREG32(RADEON_MEM_STR_CNTL) &
  2927. channel_complete_mask) ==
  2928. channel_complete_mask)
  2929. break;
  2930. }
  2931. } else {
  2932. uint32_t or_mask = RBIOS16(offset);
  2933. offset += 2;
  2934. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2935. tmp &= RADEON_SDRAM_MODE_MASK;
  2936. tmp |= or_mask;
  2937. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2938. or_mask = val << 24;
  2939. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2940. tmp &= RADEON_B3MEM_RESET_MASK;
  2941. tmp |= or_mask;
  2942. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2943. }
  2944. val = RBIOS8(offset);
  2945. }
  2946. }
  2947. }
  2948. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  2949. int mem_addr_mapping)
  2950. {
  2951. struct radeon_device *rdev = dev->dev_private;
  2952. uint32_t mem_cntl;
  2953. uint32_t mem_size;
  2954. uint32_t addr = 0;
  2955. mem_cntl = RREG32(RADEON_MEM_CNTL);
  2956. if (mem_cntl & RV100_HALF_MODE)
  2957. ram /= 2;
  2958. mem_size = ram;
  2959. mem_cntl &= ~(0xff << 8);
  2960. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  2961. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2962. RREG32(RADEON_MEM_CNTL);
  2963. /* sdram reset ? */
  2964. /* something like this???? */
  2965. while (ram--) {
  2966. addr = ram * 1024 * 1024;
  2967. /* write to each page */
  2968. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2969. WREG32(RADEON_MM_DATA, 0xdeadbeef);
  2970. /* read back and verify */
  2971. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2972. if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
  2973. return 0;
  2974. }
  2975. return mem_size;
  2976. }
  2977. static void combios_write_ram_size(struct drm_device *dev)
  2978. {
  2979. struct radeon_device *rdev = dev->dev_private;
  2980. uint8_t rev;
  2981. uint16_t offset;
  2982. uint32_t mem_size = 0;
  2983. uint32_t mem_cntl = 0;
  2984. /* should do something smarter here I guess... */
  2985. if (rdev->flags & RADEON_IS_IGP)
  2986. return;
  2987. /* first check detected mem table */
  2988. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  2989. if (offset) {
  2990. rev = RBIOS8(offset);
  2991. if (rev < 3) {
  2992. mem_cntl = RBIOS32(offset + 1);
  2993. mem_size = RBIOS16(offset + 5);
  2994. if ((rdev->family < CHIP_R200) &&
  2995. !ASIC_IS_RN50(rdev))
  2996. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2997. }
  2998. }
  2999. if (!mem_size) {
  3000. offset =
  3001. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  3002. if (offset) {
  3003. rev = RBIOS8(offset - 1);
  3004. if (rev < 1) {
  3005. if ((rdev->family < CHIP_R200)
  3006. && !ASIC_IS_RN50(rdev)) {
  3007. int ram = 0;
  3008. int mem_addr_mapping = 0;
  3009. while (RBIOS8(offset)) {
  3010. ram = RBIOS8(offset);
  3011. mem_addr_mapping =
  3012. RBIOS8(offset + 1);
  3013. if (mem_addr_mapping != 0x25)
  3014. ram *= 2;
  3015. mem_size =
  3016. combios_detect_ram(dev, ram,
  3017. mem_addr_mapping);
  3018. if (mem_size)
  3019. break;
  3020. offset += 2;
  3021. }
  3022. } else
  3023. mem_size = RBIOS8(offset);
  3024. } else {
  3025. mem_size = RBIOS8(offset);
  3026. mem_size *= 2; /* convert to MB */
  3027. }
  3028. }
  3029. }
  3030. mem_size *= (1024 * 1024); /* convert to bytes */
  3031. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  3032. }
  3033. void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
  3034. {
  3035. uint16_t dyn_clk_info =
  3036. combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3037. if (dyn_clk_info)
  3038. combios_parse_pll_table(dev, dyn_clk_info);
  3039. }
  3040. void radeon_combios_asic_init(struct drm_device *dev)
  3041. {
  3042. struct radeon_device *rdev = dev->dev_private;
  3043. uint16_t table;
  3044. /* port hardcoded mac stuff from radeonfb */
  3045. if (rdev->bios == NULL)
  3046. return;
  3047. /* ASIC INIT 1 */
  3048. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  3049. if (table)
  3050. combios_parse_mmio_table(dev, table);
  3051. /* PLL INIT */
  3052. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  3053. if (table)
  3054. combios_parse_pll_table(dev, table);
  3055. /* ASIC INIT 2 */
  3056. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  3057. if (table)
  3058. combios_parse_mmio_table(dev, table);
  3059. if (!(rdev->flags & RADEON_IS_IGP)) {
  3060. /* ASIC INIT 4 */
  3061. table =
  3062. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  3063. if (table)
  3064. combios_parse_mmio_table(dev, table);
  3065. /* RAM RESET */
  3066. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  3067. if (table)
  3068. combios_parse_ram_reset_table(dev, table);
  3069. /* ASIC INIT 3 */
  3070. table =
  3071. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  3072. if (table)
  3073. combios_parse_mmio_table(dev, table);
  3074. /* write CONFIG_MEMSIZE */
  3075. combios_write_ram_size(dev);
  3076. }
  3077. /* quirk for rs4xx HP nx6125 laptop to make it resume
  3078. * - it hangs on resume inside the dynclk 1 table.
  3079. */
  3080. if (rdev->family == CHIP_RS480 &&
  3081. rdev->pdev->subsystem_vendor == 0x103c &&
  3082. rdev->pdev->subsystem_device == 0x308b)
  3083. return;
  3084. /* quirk for rs4xx HP dv5000 laptop to make it resume
  3085. * - it hangs on resume inside the dynclk 1 table.
  3086. */
  3087. if (rdev->family == CHIP_RS480 &&
  3088. rdev->pdev->subsystem_vendor == 0x103c &&
  3089. rdev->pdev->subsystem_device == 0x30a4)
  3090. return;
  3091. /* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
  3092. * - it hangs on resume inside the dynclk 1 table.
  3093. */
  3094. if (rdev->family == CHIP_RS480 &&
  3095. rdev->pdev->subsystem_vendor == 0x103c &&
  3096. rdev->pdev->subsystem_device == 0x30ae)
  3097. return;
  3098. /* DYN CLK 1 */
  3099. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3100. if (table)
  3101. combios_parse_pll_table(dev, table);
  3102. }
  3103. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  3104. {
  3105. struct radeon_device *rdev = dev->dev_private;
  3106. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  3107. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3108. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3109. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  3110. /* let the bios control the backlight */
  3111. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  3112. /* tell the bios not to handle mode switching */
  3113. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  3114. RADEON_ACC_MODE_CHANGE);
  3115. /* tell the bios a driver is loaded */
  3116. bios_7_scratch |= RADEON_DRV_LOADED;
  3117. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3118. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3119. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  3120. }
  3121. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  3122. {
  3123. struct drm_device *dev = encoder->dev;
  3124. struct radeon_device *rdev = dev->dev_private;
  3125. uint32_t bios_6_scratch;
  3126. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3127. if (lock)
  3128. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  3129. else
  3130. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  3131. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3132. }
  3133. void
  3134. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  3135. struct drm_encoder *encoder,
  3136. bool connected)
  3137. {
  3138. struct drm_device *dev = connector->dev;
  3139. struct radeon_device *rdev = dev->dev_private;
  3140. struct radeon_connector *radeon_connector =
  3141. to_radeon_connector(connector);
  3142. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3143. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  3144. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3145. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3146. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3147. if (connected) {
  3148. DRM_DEBUG_KMS("TV1 connected\n");
  3149. /* fix me */
  3150. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  3151. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  3152. bios_5_scratch |= RADEON_TV1_ON;
  3153. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  3154. } else {
  3155. DRM_DEBUG_KMS("TV1 disconnected\n");
  3156. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  3157. bios_5_scratch &= ~RADEON_TV1_ON;
  3158. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  3159. }
  3160. }
  3161. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3162. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3163. if (connected) {
  3164. DRM_DEBUG_KMS("LCD1 connected\n");
  3165. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  3166. bios_5_scratch |= RADEON_LCD1_ON;
  3167. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  3168. } else {
  3169. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3170. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  3171. bios_5_scratch &= ~RADEON_LCD1_ON;
  3172. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  3173. }
  3174. }
  3175. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3176. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3177. if (connected) {
  3178. DRM_DEBUG_KMS("CRT1 connected\n");
  3179. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  3180. bios_5_scratch |= RADEON_CRT1_ON;
  3181. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  3182. } else {
  3183. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3184. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  3185. bios_5_scratch &= ~RADEON_CRT1_ON;
  3186. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  3187. }
  3188. }
  3189. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3190. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3191. if (connected) {
  3192. DRM_DEBUG_KMS("CRT2 connected\n");
  3193. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  3194. bios_5_scratch |= RADEON_CRT2_ON;
  3195. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  3196. } else {
  3197. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3198. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  3199. bios_5_scratch &= ~RADEON_CRT2_ON;
  3200. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  3201. }
  3202. }
  3203. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3204. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3205. if (connected) {
  3206. DRM_DEBUG_KMS("DFP1 connected\n");
  3207. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  3208. bios_5_scratch |= RADEON_DFP1_ON;
  3209. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  3210. } else {
  3211. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3212. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  3213. bios_5_scratch &= ~RADEON_DFP1_ON;
  3214. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  3215. }
  3216. }
  3217. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3218. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3219. if (connected) {
  3220. DRM_DEBUG_KMS("DFP2 connected\n");
  3221. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  3222. bios_5_scratch |= RADEON_DFP2_ON;
  3223. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  3224. } else {
  3225. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3226. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  3227. bios_5_scratch &= ~RADEON_DFP2_ON;
  3228. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  3229. }
  3230. }
  3231. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  3232. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3233. }
  3234. void
  3235. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3236. {
  3237. struct drm_device *dev = encoder->dev;
  3238. struct radeon_device *rdev = dev->dev_private;
  3239. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3240. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3241. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3242. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  3243. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  3244. }
  3245. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3246. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  3247. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  3248. }
  3249. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3250. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  3251. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  3252. }
  3253. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3254. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  3255. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  3256. }
  3257. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3258. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  3259. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  3260. }
  3261. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3262. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  3263. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  3264. }
  3265. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3266. }
  3267. void
  3268. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3269. {
  3270. struct drm_device *dev = encoder->dev;
  3271. struct radeon_device *rdev = dev->dev_private;
  3272. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3273. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3274. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  3275. if (on)
  3276. bios_6_scratch |= RADEON_TV_DPMS_ON;
  3277. else
  3278. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  3279. }
  3280. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3281. if (on)
  3282. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  3283. else
  3284. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  3285. }
  3286. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3287. if (on)
  3288. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  3289. else
  3290. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  3291. }
  3292. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  3293. if (on)
  3294. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  3295. else
  3296. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  3297. }
  3298. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3299. }