radeon_combios.c 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604
  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 if ((rdev->pdev->device == 0x4c66) &&
  1436. (rdev->pdev->subsystem_vendor == 0x1002) &&
  1437. (rdev->pdev->subsystem_device == 0x4c66)) {
  1438. /* SAM440ep RV250 embedded board */
  1439. rdev->mode_info.connector_table = CT_SAM440EP;
  1440. } else
  1441. #endif /* CONFIG_PPC_PMAC */
  1442. #ifdef CONFIG_PPC64
  1443. if (ASIC_IS_RN50(rdev))
  1444. rdev->mode_info.connector_table = CT_RN50_POWER;
  1445. else
  1446. #endif
  1447. rdev->mode_info.connector_table = CT_GENERIC;
  1448. }
  1449. switch (rdev->mode_info.connector_table) {
  1450. case CT_GENERIC:
  1451. DRM_INFO("Connector Table: %d (generic)\n",
  1452. rdev->mode_info.connector_table);
  1453. /* these are the most common settings */
  1454. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1455. /* VGA - primary dac */
  1456. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1457. hpd.hpd = RADEON_HPD_NONE;
  1458. radeon_add_legacy_encoder(dev,
  1459. radeon_get_encoder_enum(dev,
  1460. ATOM_DEVICE_CRT1_SUPPORT,
  1461. 1),
  1462. ATOM_DEVICE_CRT1_SUPPORT);
  1463. radeon_add_legacy_connector(dev, 0,
  1464. ATOM_DEVICE_CRT1_SUPPORT,
  1465. DRM_MODE_CONNECTOR_VGA,
  1466. &ddc_i2c,
  1467. CONNECTOR_OBJECT_ID_VGA,
  1468. &hpd);
  1469. } else if (rdev->flags & RADEON_IS_MOBILITY) {
  1470. /* LVDS */
  1471. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
  1472. hpd.hpd = RADEON_HPD_NONE;
  1473. radeon_add_legacy_encoder(dev,
  1474. radeon_get_encoder_enum(dev,
  1475. ATOM_DEVICE_LCD1_SUPPORT,
  1476. 0),
  1477. ATOM_DEVICE_LCD1_SUPPORT);
  1478. radeon_add_legacy_connector(dev, 0,
  1479. ATOM_DEVICE_LCD1_SUPPORT,
  1480. DRM_MODE_CONNECTOR_LVDS,
  1481. &ddc_i2c,
  1482. CONNECTOR_OBJECT_ID_LVDS,
  1483. &hpd);
  1484. /* VGA - primary dac */
  1485. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1486. hpd.hpd = RADEON_HPD_NONE;
  1487. radeon_add_legacy_encoder(dev,
  1488. radeon_get_encoder_enum(dev,
  1489. ATOM_DEVICE_CRT1_SUPPORT,
  1490. 1),
  1491. ATOM_DEVICE_CRT1_SUPPORT);
  1492. radeon_add_legacy_connector(dev, 1,
  1493. ATOM_DEVICE_CRT1_SUPPORT,
  1494. DRM_MODE_CONNECTOR_VGA,
  1495. &ddc_i2c,
  1496. CONNECTOR_OBJECT_ID_VGA,
  1497. &hpd);
  1498. } else {
  1499. /* DVI-I - tv dac, int tmds */
  1500. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1501. hpd.hpd = RADEON_HPD_1;
  1502. radeon_add_legacy_encoder(dev,
  1503. radeon_get_encoder_enum(dev,
  1504. ATOM_DEVICE_DFP1_SUPPORT,
  1505. 0),
  1506. ATOM_DEVICE_DFP1_SUPPORT);
  1507. radeon_add_legacy_encoder(dev,
  1508. radeon_get_encoder_enum(dev,
  1509. ATOM_DEVICE_CRT2_SUPPORT,
  1510. 2),
  1511. ATOM_DEVICE_CRT2_SUPPORT);
  1512. radeon_add_legacy_connector(dev, 0,
  1513. ATOM_DEVICE_DFP1_SUPPORT |
  1514. ATOM_DEVICE_CRT2_SUPPORT,
  1515. DRM_MODE_CONNECTOR_DVII,
  1516. &ddc_i2c,
  1517. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1518. &hpd);
  1519. /* VGA - primary dac */
  1520. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1521. hpd.hpd = RADEON_HPD_NONE;
  1522. radeon_add_legacy_encoder(dev,
  1523. radeon_get_encoder_enum(dev,
  1524. ATOM_DEVICE_CRT1_SUPPORT,
  1525. 1),
  1526. ATOM_DEVICE_CRT1_SUPPORT);
  1527. radeon_add_legacy_connector(dev, 1,
  1528. ATOM_DEVICE_CRT1_SUPPORT,
  1529. DRM_MODE_CONNECTOR_VGA,
  1530. &ddc_i2c,
  1531. CONNECTOR_OBJECT_ID_VGA,
  1532. &hpd);
  1533. }
  1534. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1535. /* TV - tv dac */
  1536. ddc_i2c.valid = false;
  1537. hpd.hpd = RADEON_HPD_NONE;
  1538. radeon_add_legacy_encoder(dev,
  1539. radeon_get_encoder_enum(dev,
  1540. ATOM_DEVICE_TV1_SUPPORT,
  1541. 2),
  1542. ATOM_DEVICE_TV1_SUPPORT);
  1543. radeon_add_legacy_connector(dev, 2,
  1544. ATOM_DEVICE_TV1_SUPPORT,
  1545. DRM_MODE_CONNECTOR_SVIDEO,
  1546. &ddc_i2c,
  1547. CONNECTOR_OBJECT_ID_SVIDEO,
  1548. &hpd);
  1549. }
  1550. break;
  1551. case CT_IBOOK:
  1552. DRM_INFO("Connector Table: %d (ibook)\n",
  1553. rdev->mode_info.connector_table);
  1554. /* LVDS */
  1555. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1556. hpd.hpd = RADEON_HPD_NONE;
  1557. radeon_add_legacy_encoder(dev,
  1558. radeon_get_encoder_enum(dev,
  1559. ATOM_DEVICE_LCD1_SUPPORT,
  1560. 0),
  1561. ATOM_DEVICE_LCD1_SUPPORT);
  1562. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1563. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1564. CONNECTOR_OBJECT_ID_LVDS,
  1565. &hpd);
  1566. /* VGA - TV DAC */
  1567. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1568. hpd.hpd = RADEON_HPD_NONE;
  1569. radeon_add_legacy_encoder(dev,
  1570. radeon_get_encoder_enum(dev,
  1571. ATOM_DEVICE_CRT2_SUPPORT,
  1572. 2),
  1573. ATOM_DEVICE_CRT2_SUPPORT);
  1574. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1575. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1576. CONNECTOR_OBJECT_ID_VGA,
  1577. &hpd);
  1578. /* TV - TV DAC */
  1579. ddc_i2c.valid = false;
  1580. hpd.hpd = RADEON_HPD_NONE;
  1581. radeon_add_legacy_encoder(dev,
  1582. radeon_get_encoder_enum(dev,
  1583. ATOM_DEVICE_TV1_SUPPORT,
  1584. 2),
  1585. ATOM_DEVICE_TV1_SUPPORT);
  1586. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1587. DRM_MODE_CONNECTOR_SVIDEO,
  1588. &ddc_i2c,
  1589. CONNECTOR_OBJECT_ID_SVIDEO,
  1590. &hpd);
  1591. break;
  1592. case CT_POWERBOOK_EXTERNAL:
  1593. DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
  1594. rdev->mode_info.connector_table);
  1595. /* LVDS */
  1596. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1597. hpd.hpd = RADEON_HPD_NONE;
  1598. radeon_add_legacy_encoder(dev,
  1599. radeon_get_encoder_enum(dev,
  1600. ATOM_DEVICE_LCD1_SUPPORT,
  1601. 0),
  1602. ATOM_DEVICE_LCD1_SUPPORT);
  1603. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1604. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1605. CONNECTOR_OBJECT_ID_LVDS,
  1606. &hpd);
  1607. /* DVI-I - primary dac, ext tmds */
  1608. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1609. hpd.hpd = RADEON_HPD_2; /* ??? */
  1610. radeon_add_legacy_encoder(dev,
  1611. radeon_get_encoder_enum(dev,
  1612. ATOM_DEVICE_DFP2_SUPPORT,
  1613. 0),
  1614. ATOM_DEVICE_DFP2_SUPPORT);
  1615. radeon_add_legacy_encoder(dev,
  1616. radeon_get_encoder_enum(dev,
  1617. ATOM_DEVICE_CRT1_SUPPORT,
  1618. 1),
  1619. ATOM_DEVICE_CRT1_SUPPORT);
  1620. /* XXX some are SL */
  1621. radeon_add_legacy_connector(dev, 1,
  1622. ATOM_DEVICE_DFP2_SUPPORT |
  1623. ATOM_DEVICE_CRT1_SUPPORT,
  1624. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1625. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1626. &hpd);
  1627. /* TV - TV DAC */
  1628. ddc_i2c.valid = false;
  1629. hpd.hpd = RADEON_HPD_NONE;
  1630. radeon_add_legacy_encoder(dev,
  1631. radeon_get_encoder_enum(dev,
  1632. ATOM_DEVICE_TV1_SUPPORT,
  1633. 2),
  1634. ATOM_DEVICE_TV1_SUPPORT);
  1635. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1636. DRM_MODE_CONNECTOR_SVIDEO,
  1637. &ddc_i2c,
  1638. CONNECTOR_OBJECT_ID_SVIDEO,
  1639. &hpd);
  1640. break;
  1641. case CT_POWERBOOK_INTERNAL:
  1642. DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
  1643. rdev->mode_info.connector_table);
  1644. /* LVDS */
  1645. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1646. hpd.hpd = RADEON_HPD_NONE;
  1647. radeon_add_legacy_encoder(dev,
  1648. radeon_get_encoder_enum(dev,
  1649. ATOM_DEVICE_LCD1_SUPPORT,
  1650. 0),
  1651. ATOM_DEVICE_LCD1_SUPPORT);
  1652. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1653. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1654. CONNECTOR_OBJECT_ID_LVDS,
  1655. &hpd);
  1656. /* DVI-I - primary dac, int tmds */
  1657. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1658. hpd.hpd = RADEON_HPD_1; /* ??? */
  1659. radeon_add_legacy_encoder(dev,
  1660. radeon_get_encoder_enum(dev,
  1661. ATOM_DEVICE_DFP1_SUPPORT,
  1662. 0),
  1663. ATOM_DEVICE_DFP1_SUPPORT);
  1664. radeon_add_legacy_encoder(dev,
  1665. radeon_get_encoder_enum(dev,
  1666. ATOM_DEVICE_CRT1_SUPPORT,
  1667. 1),
  1668. ATOM_DEVICE_CRT1_SUPPORT);
  1669. radeon_add_legacy_connector(dev, 1,
  1670. ATOM_DEVICE_DFP1_SUPPORT |
  1671. ATOM_DEVICE_CRT1_SUPPORT,
  1672. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1673. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1674. &hpd);
  1675. /* TV - TV DAC */
  1676. ddc_i2c.valid = false;
  1677. hpd.hpd = RADEON_HPD_NONE;
  1678. radeon_add_legacy_encoder(dev,
  1679. radeon_get_encoder_enum(dev,
  1680. ATOM_DEVICE_TV1_SUPPORT,
  1681. 2),
  1682. ATOM_DEVICE_TV1_SUPPORT);
  1683. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1684. DRM_MODE_CONNECTOR_SVIDEO,
  1685. &ddc_i2c,
  1686. CONNECTOR_OBJECT_ID_SVIDEO,
  1687. &hpd);
  1688. break;
  1689. case CT_POWERBOOK_VGA:
  1690. DRM_INFO("Connector Table: %d (powerbook vga)\n",
  1691. rdev->mode_info.connector_table);
  1692. /* LVDS */
  1693. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1694. hpd.hpd = RADEON_HPD_NONE;
  1695. radeon_add_legacy_encoder(dev,
  1696. radeon_get_encoder_enum(dev,
  1697. ATOM_DEVICE_LCD1_SUPPORT,
  1698. 0),
  1699. ATOM_DEVICE_LCD1_SUPPORT);
  1700. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1701. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1702. CONNECTOR_OBJECT_ID_LVDS,
  1703. &hpd);
  1704. /* VGA - primary dac */
  1705. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1706. hpd.hpd = RADEON_HPD_NONE;
  1707. radeon_add_legacy_encoder(dev,
  1708. radeon_get_encoder_enum(dev,
  1709. ATOM_DEVICE_CRT1_SUPPORT,
  1710. 1),
  1711. ATOM_DEVICE_CRT1_SUPPORT);
  1712. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
  1713. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1714. CONNECTOR_OBJECT_ID_VGA,
  1715. &hpd);
  1716. /* TV - TV DAC */
  1717. ddc_i2c.valid = false;
  1718. hpd.hpd = RADEON_HPD_NONE;
  1719. radeon_add_legacy_encoder(dev,
  1720. radeon_get_encoder_enum(dev,
  1721. ATOM_DEVICE_TV1_SUPPORT,
  1722. 2),
  1723. ATOM_DEVICE_TV1_SUPPORT);
  1724. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1725. DRM_MODE_CONNECTOR_SVIDEO,
  1726. &ddc_i2c,
  1727. CONNECTOR_OBJECT_ID_SVIDEO,
  1728. &hpd);
  1729. break;
  1730. case CT_MINI_EXTERNAL:
  1731. DRM_INFO("Connector Table: %d (mini external tmds)\n",
  1732. rdev->mode_info.connector_table);
  1733. /* DVI-I - tv dac, ext tmds */
  1734. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1735. hpd.hpd = RADEON_HPD_2; /* ??? */
  1736. radeon_add_legacy_encoder(dev,
  1737. radeon_get_encoder_enum(dev,
  1738. ATOM_DEVICE_DFP2_SUPPORT,
  1739. 0),
  1740. ATOM_DEVICE_DFP2_SUPPORT);
  1741. radeon_add_legacy_encoder(dev,
  1742. radeon_get_encoder_enum(dev,
  1743. ATOM_DEVICE_CRT2_SUPPORT,
  1744. 2),
  1745. ATOM_DEVICE_CRT2_SUPPORT);
  1746. /* XXX are any DL? */
  1747. radeon_add_legacy_connector(dev, 0,
  1748. ATOM_DEVICE_DFP2_SUPPORT |
  1749. ATOM_DEVICE_CRT2_SUPPORT,
  1750. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1751. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1752. &hpd);
  1753. /* TV - TV DAC */
  1754. ddc_i2c.valid = false;
  1755. hpd.hpd = RADEON_HPD_NONE;
  1756. radeon_add_legacy_encoder(dev,
  1757. radeon_get_encoder_enum(dev,
  1758. ATOM_DEVICE_TV1_SUPPORT,
  1759. 2),
  1760. ATOM_DEVICE_TV1_SUPPORT);
  1761. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1762. DRM_MODE_CONNECTOR_SVIDEO,
  1763. &ddc_i2c,
  1764. CONNECTOR_OBJECT_ID_SVIDEO,
  1765. &hpd);
  1766. break;
  1767. case CT_MINI_INTERNAL:
  1768. DRM_INFO("Connector Table: %d (mini internal tmds)\n",
  1769. rdev->mode_info.connector_table);
  1770. /* DVI-I - tv dac, int tmds */
  1771. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1772. hpd.hpd = RADEON_HPD_1; /* ??? */
  1773. radeon_add_legacy_encoder(dev,
  1774. radeon_get_encoder_enum(dev,
  1775. ATOM_DEVICE_DFP1_SUPPORT,
  1776. 0),
  1777. ATOM_DEVICE_DFP1_SUPPORT);
  1778. radeon_add_legacy_encoder(dev,
  1779. radeon_get_encoder_enum(dev,
  1780. ATOM_DEVICE_CRT2_SUPPORT,
  1781. 2),
  1782. ATOM_DEVICE_CRT2_SUPPORT);
  1783. radeon_add_legacy_connector(dev, 0,
  1784. ATOM_DEVICE_DFP1_SUPPORT |
  1785. ATOM_DEVICE_CRT2_SUPPORT,
  1786. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1787. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1788. &hpd);
  1789. /* TV - TV DAC */
  1790. ddc_i2c.valid = false;
  1791. hpd.hpd = RADEON_HPD_NONE;
  1792. radeon_add_legacy_encoder(dev,
  1793. radeon_get_encoder_enum(dev,
  1794. ATOM_DEVICE_TV1_SUPPORT,
  1795. 2),
  1796. ATOM_DEVICE_TV1_SUPPORT);
  1797. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1798. DRM_MODE_CONNECTOR_SVIDEO,
  1799. &ddc_i2c,
  1800. CONNECTOR_OBJECT_ID_SVIDEO,
  1801. &hpd);
  1802. break;
  1803. case CT_IMAC_G5_ISIGHT:
  1804. DRM_INFO("Connector Table: %d (imac g5 isight)\n",
  1805. rdev->mode_info.connector_table);
  1806. /* DVI-D - int tmds */
  1807. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1808. hpd.hpd = RADEON_HPD_1; /* ??? */
  1809. radeon_add_legacy_encoder(dev,
  1810. radeon_get_encoder_enum(dev,
  1811. ATOM_DEVICE_DFP1_SUPPORT,
  1812. 0),
  1813. ATOM_DEVICE_DFP1_SUPPORT);
  1814. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
  1815. DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
  1816. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  1817. &hpd);
  1818. /* VGA - tv dac */
  1819. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1820. hpd.hpd = RADEON_HPD_NONE;
  1821. radeon_add_legacy_encoder(dev,
  1822. radeon_get_encoder_enum(dev,
  1823. ATOM_DEVICE_CRT2_SUPPORT,
  1824. 2),
  1825. ATOM_DEVICE_CRT2_SUPPORT);
  1826. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1827. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1828. CONNECTOR_OBJECT_ID_VGA,
  1829. &hpd);
  1830. /* TV - TV DAC */
  1831. ddc_i2c.valid = false;
  1832. hpd.hpd = RADEON_HPD_NONE;
  1833. radeon_add_legacy_encoder(dev,
  1834. radeon_get_encoder_enum(dev,
  1835. ATOM_DEVICE_TV1_SUPPORT,
  1836. 2),
  1837. ATOM_DEVICE_TV1_SUPPORT);
  1838. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1839. DRM_MODE_CONNECTOR_SVIDEO,
  1840. &ddc_i2c,
  1841. CONNECTOR_OBJECT_ID_SVIDEO,
  1842. &hpd);
  1843. break;
  1844. case CT_EMAC:
  1845. DRM_INFO("Connector Table: %d (emac)\n",
  1846. rdev->mode_info.connector_table);
  1847. /* VGA - primary dac */
  1848. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1849. hpd.hpd = RADEON_HPD_NONE;
  1850. radeon_add_legacy_encoder(dev,
  1851. radeon_get_encoder_enum(dev,
  1852. ATOM_DEVICE_CRT1_SUPPORT,
  1853. 1),
  1854. ATOM_DEVICE_CRT1_SUPPORT);
  1855. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1856. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1857. CONNECTOR_OBJECT_ID_VGA,
  1858. &hpd);
  1859. /* VGA - tv dac */
  1860. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1861. hpd.hpd = RADEON_HPD_NONE;
  1862. radeon_add_legacy_encoder(dev,
  1863. radeon_get_encoder_enum(dev,
  1864. ATOM_DEVICE_CRT2_SUPPORT,
  1865. 2),
  1866. ATOM_DEVICE_CRT2_SUPPORT);
  1867. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1868. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1869. CONNECTOR_OBJECT_ID_VGA,
  1870. &hpd);
  1871. /* TV - TV DAC */
  1872. ddc_i2c.valid = false;
  1873. hpd.hpd = RADEON_HPD_NONE;
  1874. radeon_add_legacy_encoder(dev,
  1875. radeon_get_encoder_enum(dev,
  1876. ATOM_DEVICE_TV1_SUPPORT,
  1877. 2),
  1878. ATOM_DEVICE_TV1_SUPPORT);
  1879. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1880. DRM_MODE_CONNECTOR_SVIDEO,
  1881. &ddc_i2c,
  1882. CONNECTOR_OBJECT_ID_SVIDEO,
  1883. &hpd);
  1884. break;
  1885. case CT_RN50_POWER:
  1886. DRM_INFO("Connector Table: %d (rn50-power)\n",
  1887. rdev->mode_info.connector_table);
  1888. /* VGA - primary dac */
  1889. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1890. hpd.hpd = RADEON_HPD_NONE;
  1891. radeon_add_legacy_encoder(dev,
  1892. radeon_get_encoder_enum(dev,
  1893. ATOM_DEVICE_CRT1_SUPPORT,
  1894. 1),
  1895. ATOM_DEVICE_CRT1_SUPPORT);
  1896. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1897. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1898. CONNECTOR_OBJECT_ID_VGA,
  1899. &hpd);
  1900. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  1901. hpd.hpd = RADEON_HPD_NONE;
  1902. radeon_add_legacy_encoder(dev,
  1903. radeon_get_encoder_enum(dev,
  1904. ATOM_DEVICE_CRT2_SUPPORT,
  1905. 2),
  1906. ATOM_DEVICE_CRT2_SUPPORT);
  1907. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1908. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1909. CONNECTOR_OBJECT_ID_VGA,
  1910. &hpd);
  1911. break;
  1912. case CT_MAC_X800:
  1913. DRM_INFO("Connector Table: %d (mac x800)\n",
  1914. rdev->mode_info.connector_table);
  1915. /* DVI - primary dac, internal tmds */
  1916. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1917. hpd.hpd = RADEON_HPD_1; /* ??? */
  1918. radeon_add_legacy_encoder(dev,
  1919. radeon_get_encoder_enum(dev,
  1920. ATOM_DEVICE_DFP1_SUPPORT,
  1921. 0),
  1922. ATOM_DEVICE_DFP1_SUPPORT);
  1923. radeon_add_legacy_encoder(dev,
  1924. radeon_get_encoder_enum(dev,
  1925. ATOM_DEVICE_CRT1_SUPPORT,
  1926. 1),
  1927. ATOM_DEVICE_CRT1_SUPPORT);
  1928. radeon_add_legacy_connector(dev, 0,
  1929. ATOM_DEVICE_DFP1_SUPPORT |
  1930. ATOM_DEVICE_CRT1_SUPPORT,
  1931. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1932. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1933. &hpd);
  1934. /* DVI - tv dac, dvo */
  1935. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  1936. hpd.hpd = RADEON_HPD_2; /* ??? */
  1937. radeon_add_legacy_encoder(dev,
  1938. radeon_get_encoder_enum(dev,
  1939. ATOM_DEVICE_DFP2_SUPPORT,
  1940. 0),
  1941. ATOM_DEVICE_DFP2_SUPPORT);
  1942. radeon_add_legacy_encoder(dev,
  1943. radeon_get_encoder_enum(dev,
  1944. ATOM_DEVICE_CRT2_SUPPORT,
  1945. 2),
  1946. ATOM_DEVICE_CRT2_SUPPORT);
  1947. radeon_add_legacy_connector(dev, 1,
  1948. ATOM_DEVICE_DFP2_SUPPORT |
  1949. ATOM_DEVICE_CRT2_SUPPORT,
  1950. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1951. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1952. &hpd);
  1953. break;
  1954. case CT_MAC_G5_9600:
  1955. DRM_INFO("Connector Table: %d (mac g5 9600)\n",
  1956. rdev->mode_info.connector_table);
  1957. /* DVI - tv dac, dvo */
  1958. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  1959. hpd.hpd = RADEON_HPD_1; /* ??? */
  1960. radeon_add_legacy_encoder(dev,
  1961. radeon_get_encoder_enum(dev,
  1962. ATOM_DEVICE_DFP2_SUPPORT,
  1963. 0),
  1964. ATOM_DEVICE_DFP2_SUPPORT);
  1965. radeon_add_legacy_encoder(dev,
  1966. radeon_get_encoder_enum(dev,
  1967. ATOM_DEVICE_CRT2_SUPPORT,
  1968. 2),
  1969. ATOM_DEVICE_CRT2_SUPPORT);
  1970. radeon_add_legacy_connector(dev, 0,
  1971. ATOM_DEVICE_DFP2_SUPPORT |
  1972. ATOM_DEVICE_CRT2_SUPPORT,
  1973. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1974. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1975. &hpd);
  1976. /* ADC - primary dac, internal tmds */
  1977. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  1978. hpd.hpd = RADEON_HPD_2; /* ??? */
  1979. radeon_add_legacy_encoder(dev,
  1980. radeon_get_encoder_enum(dev,
  1981. ATOM_DEVICE_DFP1_SUPPORT,
  1982. 0),
  1983. ATOM_DEVICE_DFP1_SUPPORT);
  1984. radeon_add_legacy_encoder(dev,
  1985. radeon_get_encoder_enum(dev,
  1986. ATOM_DEVICE_CRT1_SUPPORT,
  1987. 1),
  1988. ATOM_DEVICE_CRT1_SUPPORT);
  1989. radeon_add_legacy_connector(dev, 1,
  1990. ATOM_DEVICE_DFP1_SUPPORT |
  1991. ATOM_DEVICE_CRT1_SUPPORT,
  1992. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1993. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1994. &hpd);
  1995. /* TV - TV DAC */
  1996. ddc_i2c.valid = false;
  1997. hpd.hpd = RADEON_HPD_NONE;
  1998. radeon_add_legacy_encoder(dev,
  1999. radeon_get_encoder_enum(dev,
  2000. ATOM_DEVICE_TV1_SUPPORT,
  2001. 2),
  2002. ATOM_DEVICE_TV1_SUPPORT);
  2003. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  2004. DRM_MODE_CONNECTOR_SVIDEO,
  2005. &ddc_i2c,
  2006. CONNECTOR_OBJECT_ID_SVIDEO,
  2007. &hpd);
  2008. break;
  2009. case CT_SAM440EP:
  2010. DRM_INFO("Connector Table: %d (SAM440ep embedded board)\n",
  2011. rdev->mode_info.connector_table);
  2012. /* LVDS */
  2013. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
  2014. hpd.hpd = RADEON_HPD_NONE;
  2015. radeon_add_legacy_encoder(dev,
  2016. radeon_get_encoder_enum(dev,
  2017. ATOM_DEVICE_LCD1_SUPPORT,
  2018. 0),
  2019. ATOM_DEVICE_LCD1_SUPPORT);
  2020. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  2021. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  2022. CONNECTOR_OBJECT_ID_LVDS,
  2023. &hpd);
  2024. /* DVI-I - secondary dac, int tmds */
  2025. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  2026. hpd.hpd = RADEON_HPD_1; /* ??? */
  2027. radeon_add_legacy_encoder(dev,
  2028. radeon_get_encoder_enum(dev,
  2029. ATOM_DEVICE_DFP1_SUPPORT,
  2030. 0),
  2031. ATOM_DEVICE_DFP1_SUPPORT);
  2032. radeon_add_legacy_encoder(dev,
  2033. radeon_get_encoder_enum(dev,
  2034. ATOM_DEVICE_CRT2_SUPPORT,
  2035. 2),
  2036. ATOM_DEVICE_CRT2_SUPPORT);
  2037. radeon_add_legacy_connector(dev, 1,
  2038. ATOM_DEVICE_DFP1_SUPPORT |
  2039. ATOM_DEVICE_CRT2_SUPPORT,
  2040. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  2041. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2042. &hpd);
  2043. /* VGA - primary dac */
  2044. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  2045. hpd.hpd = RADEON_HPD_NONE;
  2046. radeon_add_legacy_encoder(dev,
  2047. radeon_get_encoder_enum(dev,
  2048. ATOM_DEVICE_CRT1_SUPPORT,
  2049. 1),
  2050. ATOM_DEVICE_CRT1_SUPPORT);
  2051. radeon_add_legacy_connector(dev, 2,
  2052. ATOM_DEVICE_CRT1_SUPPORT,
  2053. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  2054. CONNECTOR_OBJECT_ID_VGA,
  2055. &hpd);
  2056. /* TV - TV DAC */
  2057. ddc_i2c.valid = false;
  2058. hpd.hpd = RADEON_HPD_NONE;
  2059. radeon_add_legacy_encoder(dev,
  2060. radeon_get_encoder_enum(dev,
  2061. ATOM_DEVICE_TV1_SUPPORT,
  2062. 2),
  2063. ATOM_DEVICE_TV1_SUPPORT);
  2064. radeon_add_legacy_connector(dev, 3, ATOM_DEVICE_TV1_SUPPORT,
  2065. DRM_MODE_CONNECTOR_SVIDEO,
  2066. &ddc_i2c,
  2067. CONNECTOR_OBJECT_ID_SVIDEO,
  2068. &hpd);
  2069. break;
  2070. default:
  2071. DRM_INFO("Connector table: %d (invalid)\n",
  2072. rdev->mode_info.connector_table);
  2073. return false;
  2074. }
  2075. radeon_link_encoder_connector(dev);
  2076. return true;
  2077. }
  2078. static bool radeon_apply_legacy_quirks(struct drm_device *dev,
  2079. int bios_index,
  2080. enum radeon_combios_connector
  2081. *legacy_connector,
  2082. struct radeon_i2c_bus_rec *ddc_i2c,
  2083. struct radeon_hpd *hpd)
  2084. {
  2085. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  2086. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  2087. if (dev->pdev->device == 0x515e &&
  2088. dev->pdev->subsystem_vendor == 0x1014) {
  2089. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  2090. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  2091. return false;
  2092. }
  2093. /* X300 card with extra non-existent DVI port */
  2094. if (dev->pdev->device == 0x5B60 &&
  2095. dev->pdev->subsystem_vendor == 0x17af &&
  2096. dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  2097. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  2098. return false;
  2099. }
  2100. return true;
  2101. }
  2102. static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
  2103. {
  2104. /* Acer 5102 has non-existent TV port */
  2105. if (dev->pdev->device == 0x5975 &&
  2106. dev->pdev->subsystem_vendor == 0x1025 &&
  2107. dev->pdev->subsystem_device == 0x009f)
  2108. return false;
  2109. /* HP dc5750 has non-existent TV port */
  2110. if (dev->pdev->device == 0x5974 &&
  2111. dev->pdev->subsystem_vendor == 0x103c &&
  2112. dev->pdev->subsystem_device == 0x280a)
  2113. return false;
  2114. /* MSI S270 has non-existent TV port */
  2115. if (dev->pdev->device == 0x5955 &&
  2116. dev->pdev->subsystem_vendor == 0x1462 &&
  2117. dev->pdev->subsystem_device == 0x0131)
  2118. return false;
  2119. return true;
  2120. }
  2121. static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
  2122. {
  2123. struct radeon_device *rdev = dev->dev_private;
  2124. uint32_t ext_tmds_info;
  2125. if (rdev->flags & RADEON_IS_IGP) {
  2126. if (is_dvi_d)
  2127. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2128. else
  2129. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2130. }
  2131. ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2132. if (ext_tmds_info) {
  2133. uint8_t rev = RBIOS8(ext_tmds_info);
  2134. uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
  2135. if (rev >= 3) {
  2136. if (is_dvi_d)
  2137. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2138. else
  2139. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2140. } else {
  2141. if (flags & 1) {
  2142. if (is_dvi_d)
  2143. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2144. else
  2145. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2146. }
  2147. }
  2148. }
  2149. if (is_dvi_d)
  2150. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2151. else
  2152. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2153. }
  2154. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  2155. {
  2156. struct radeon_device *rdev = dev->dev_private;
  2157. uint32_t conn_info, entry, devices;
  2158. uint16_t tmp, connector_object_id;
  2159. enum radeon_combios_ddc ddc_type;
  2160. enum radeon_combios_connector connector;
  2161. int i = 0;
  2162. struct radeon_i2c_bus_rec ddc_i2c;
  2163. struct radeon_hpd hpd;
  2164. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  2165. if (conn_info) {
  2166. for (i = 0; i < 4; i++) {
  2167. entry = conn_info + 2 + i * 2;
  2168. if (!RBIOS16(entry))
  2169. break;
  2170. tmp = RBIOS16(entry);
  2171. connector = (tmp >> 12) & 0xf;
  2172. ddc_type = (tmp >> 8) & 0xf;
  2173. ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2174. switch (connector) {
  2175. case CONNECTOR_PROPRIETARY_LEGACY:
  2176. case CONNECTOR_DVI_I_LEGACY:
  2177. case CONNECTOR_DVI_D_LEGACY:
  2178. if ((tmp >> 4) & 0x1)
  2179. hpd.hpd = RADEON_HPD_2;
  2180. else
  2181. hpd.hpd = RADEON_HPD_1;
  2182. break;
  2183. default:
  2184. hpd.hpd = RADEON_HPD_NONE;
  2185. break;
  2186. }
  2187. if (!radeon_apply_legacy_quirks(dev, i, &connector,
  2188. &ddc_i2c, &hpd))
  2189. continue;
  2190. switch (connector) {
  2191. case CONNECTOR_PROPRIETARY_LEGACY:
  2192. if ((tmp >> 4) & 0x1)
  2193. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2194. else
  2195. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2196. radeon_add_legacy_encoder(dev,
  2197. radeon_get_encoder_enum
  2198. (dev, devices, 0),
  2199. devices);
  2200. radeon_add_legacy_connector(dev, i, devices,
  2201. legacy_connector_convert
  2202. [connector],
  2203. &ddc_i2c,
  2204. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  2205. &hpd);
  2206. break;
  2207. case CONNECTOR_CRT_LEGACY:
  2208. if (tmp & 0x1) {
  2209. devices = ATOM_DEVICE_CRT2_SUPPORT;
  2210. radeon_add_legacy_encoder(dev,
  2211. radeon_get_encoder_enum
  2212. (dev,
  2213. ATOM_DEVICE_CRT2_SUPPORT,
  2214. 2),
  2215. ATOM_DEVICE_CRT2_SUPPORT);
  2216. } else {
  2217. devices = ATOM_DEVICE_CRT1_SUPPORT;
  2218. radeon_add_legacy_encoder(dev,
  2219. radeon_get_encoder_enum
  2220. (dev,
  2221. ATOM_DEVICE_CRT1_SUPPORT,
  2222. 1),
  2223. ATOM_DEVICE_CRT1_SUPPORT);
  2224. }
  2225. radeon_add_legacy_connector(dev,
  2226. i,
  2227. devices,
  2228. legacy_connector_convert
  2229. [connector],
  2230. &ddc_i2c,
  2231. CONNECTOR_OBJECT_ID_VGA,
  2232. &hpd);
  2233. break;
  2234. case CONNECTOR_DVI_I_LEGACY:
  2235. devices = 0;
  2236. if (tmp & 0x1) {
  2237. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  2238. radeon_add_legacy_encoder(dev,
  2239. radeon_get_encoder_enum
  2240. (dev,
  2241. ATOM_DEVICE_CRT2_SUPPORT,
  2242. 2),
  2243. ATOM_DEVICE_CRT2_SUPPORT);
  2244. } else {
  2245. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  2246. radeon_add_legacy_encoder(dev,
  2247. radeon_get_encoder_enum
  2248. (dev,
  2249. ATOM_DEVICE_CRT1_SUPPORT,
  2250. 1),
  2251. ATOM_DEVICE_CRT1_SUPPORT);
  2252. }
  2253. if ((tmp >> 4) & 0x1) {
  2254. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  2255. radeon_add_legacy_encoder(dev,
  2256. radeon_get_encoder_enum
  2257. (dev,
  2258. ATOM_DEVICE_DFP2_SUPPORT,
  2259. 0),
  2260. ATOM_DEVICE_DFP2_SUPPORT);
  2261. connector_object_id = combios_check_dl_dvi(dev, 0);
  2262. } else {
  2263. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  2264. radeon_add_legacy_encoder(dev,
  2265. radeon_get_encoder_enum
  2266. (dev,
  2267. ATOM_DEVICE_DFP1_SUPPORT,
  2268. 0),
  2269. ATOM_DEVICE_DFP1_SUPPORT);
  2270. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2271. }
  2272. radeon_add_legacy_connector(dev,
  2273. i,
  2274. devices,
  2275. legacy_connector_convert
  2276. [connector],
  2277. &ddc_i2c,
  2278. connector_object_id,
  2279. &hpd);
  2280. break;
  2281. case CONNECTOR_DVI_D_LEGACY:
  2282. if ((tmp >> 4) & 0x1) {
  2283. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2284. connector_object_id = combios_check_dl_dvi(dev, 1);
  2285. } else {
  2286. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2287. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2288. }
  2289. radeon_add_legacy_encoder(dev,
  2290. radeon_get_encoder_enum
  2291. (dev, devices, 0),
  2292. devices);
  2293. radeon_add_legacy_connector(dev, i, devices,
  2294. legacy_connector_convert
  2295. [connector],
  2296. &ddc_i2c,
  2297. connector_object_id,
  2298. &hpd);
  2299. break;
  2300. case CONNECTOR_CTV_LEGACY:
  2301. case CONNECTOR_STV_LEGACY:
  2302. radeon_add_legacy_encoder(dev,
  2303. radeon_get_encoder_enum
  2304. (dev,
  2305. ATOM_DEVICE_TV1_SUPPORT,
  2306. 2),
  2307. ATOM_DEVICE_TV1_SUPPORT);
  2308. radeon_add_legacy_connector(dev, i,
  2309. ATOM_DEVICE_TV1_SUPPORT,
  2310. legacy_connector_convert
  2311. [connector],
  2312. &ddc_i2c,
  2313. CONNECTOR_OBJECT_ID_SVIDEO,
  2314. &hpd);
  2315. break;
  2316. default:
  2317. DRM_ERROR("Unknown connector type: %d\n",
  2318. connector);
  2319. continue;
  2320. }
  2321. }
  2322. } else {
  2323. uint16_t tmds_info =
  2324. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  2325. if (tmds_info) {
  2326. DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
  2327. radeon_add_legacy_encoder(dev,
  2328. radeon_get_encoder_enum(dev,
  2329. ATOM_DEVICE_CRT1_SUPPORT,
  2330. 1),
  2331. ATOM_DEVICE_CRT1_SUPPORT);
  2332. radeon_add_legacy_encoder(dev,
  2333. radeon_get_encoder_enum(dev,
  2334. ATOM_DEVICE_DFP1_SUPPORT,
  2335. 0),
  2336. ATOM_DEVICE_DFP1_SUPPORT);
  2337. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  2338. hpd.hpd = RADEON_HPD_1;
  2339. radeon_add_legacy_connector(dev,
  2340. 0,
  2341. ATOM_DEVICE_CRT1_SUPPORT |
  2342. ATOM_DEVICE_DFP1_SUPPORT,
  2343. DRM_MODE_CONNECTOR_DVII,
  2344. &ddc_i2c,
  2345. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2346. &hpd);
  2347. } else {
  2348. uint16_t crt_info =
  2349. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  2350. DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
  2351. if (crt_info) {
  2352. radeon_add_legacy_encoder(dev,
  2353. radeon_get_encoder_enum(dev,
  2354. ATOM_DEVICE_CRT1_SUPPORT,
  2355. 1),
  2356. ATOM_DEVICE_CRT1_SUPPORT);
  2357. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  2358. hpd.hpd = RADEON_HPD_NONE;
  2359. radeon_add_legacy_connector(dev,
  2360. 0,
  2361. ATOM_DEVICE_CRT1_SUPPORT,
  2362. DRM_MODE_CONNECTOR_VGA,
  2363. &ddc_i2c,
  2364. CONNECTOR_OBJECT_ID_VGA,
  2365. &hpd);
  2366. } else {
  2367. DRM_DEBUG_KMS("No connector info found\n");
  2368. return false;
  2369. }
  2370. }
  2371. }
  2372. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  2373. uint16_t lcd_info =
  2374. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  2375. if (lcd_info) {
  2376. uint16_t lcd_ddc_info =
  2377. combios_get_table_offset(dev,
  2378. COMBIOS_LCD_DDC_INFO_TABLE);
  2379. radeon_add_legacy_encoder(dev,
  2380. radeon_get_encoder_enum(dev,
  2381. ATOM_DEVICE_LCD1_SUPPORT,
  2382. 0),
  2383. ATOM_DEVICE_LCD1_SUPPORT);
  2384. if (lcd_ddc_info) {
  2385. ddc_type = RBIOS8(lcd_ddc_info + 2);
  2386. switch (ddc_type) {
  2387. case DDC_LCD:
  2388. ddc_i2c =
  2389. combios_setup_i2c_bus(rdev,
  2390. DDC_LCD,
  2391. RBIOS32(lcd_ddc_info + 3),
  2392. RBIOS32(lcd_ddc_info + 7));
  2393. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2394. break;
  2395. case DDC_GPIO:
  2396. ddc_i2c =
  2397. combios_setup_i2c_bus(rdev,
  2398. DDC_GPIO,
  2399. RBIOS32(lcd_ddc_info + 3),
  2400. RBIOS32(lcd_ddc_info + 7));
  2401. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2402. break;
  2403. default:
  2404. ddc_i2c =
  2405. combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2406. break;
  2407. }
  2408. DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
  2409. } else
  2410. ddc_i2c.valid = false;
  2411. hpd.hpd = RADEON_HPD_NONE;
  2412. radeon_add_legacy_connector(dev,
  2413. 5,
  2414. ATOM_DEVICE_LCD1_SUPPORT,
  2415. DRM_MODE_CONNECTOR_LVDS,
  2416. &ddc_i2c,
  2417. CONNECTOR_OBJECT_ID_LVDS,
  2418. &hpd);
  2419. }
  2420. }
  2421. /* check TV table */
  2422. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  2423. uint32_t tv_info =
  2424. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  2425. if (tv_info) {
  2426. if (RBIOS8(tv_info + 6) == 'T') {
  2427. if (radeon_apply_legacy_tv_quirks(dev)) {
  2428. hpd.hpd = RADEON_HPD_NONE;
  2429. ddc_i2c.valid = false;
  2430. radeon_add_legacy_encoder(dev,
  2431. radeon_get_encoder_enum
  2432. (dev,
  2433. ATOM_DEVICE_TV1_SUPPORT,
  2434. 2),
  2435. ATOM_DEVICE_TV1_SUPPORT);
  2436. radeon_add_legacy_connector(dev, 6,
  2437. ATOM_DEVICE_TV1_SUPPORT,
  2438. DRM_MODE_CONNECTOR_SVIDEO,
  2439. &ddc_i2c,
  2440. CONNECTOR_OBJECT_ID_SVIDEO,
  2441. &hpd);
  2442. }
  2443. }
  2444. }
  2445. }
  2446. radeon_link_encoder_connector(dev);
  2447. return true;
  2448. }
  2449. static const char *thermal_controller_names[] = {
  2450. "NONE",
  2451. "lm63",
  2452. "adm1032",
  2453. };
  2454. void radeon_combios_get_power_modes(struct radeon_device *rdev)
  2455. {
  2456. struct drm_device *dev = rdev->ddev;
  2457. u16 offset, misc, misc2 = 0;
  2458. u8 rev, blocks, tmp;
  2459. int state_index = 0;
  2460. struct radeon_i2c_bus_rec i2c_bus;
  2461. rdev->pm.default_power_state_index = -1;
  2462. /* allocate 2 power states */
  2463. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
  2464. if (rdev->pm.power_state) {
  2465. /* allocate 1 clock mode per state */
  2466. rdev->pm.power_state[0].clock_info =
  2467. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2468. rdev->pm.power_state[1].clock_info =
  2469. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2470. if (!rdev->pm.power_state[0].clock_info ||
  2471. !rdev->pm.power_state[1].clock_info)
  2472. goto pm_failed;
  2473. } else
  2474. goto pm_failed;
  2475. /* check for a thermal chip */
  2476. offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
  2477. if (offset) {
  2478. u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
  2479. rev = RBIOS8(offset);
  2480. if (rev == 0) {
  2481. thermal_controller = RBIOS8(offset + 3);
  2482. gpio = RBIOS8(offset + 4) & 0x3f;
  2483. i2c_addr = RBIOS8(offset + 5);
  2484. } else if (rev == 1) {
  2485. thermal_controller = RBIOS8(offset + 4);
  2486. gpio = RBIOS8(offset + 5) & 0x3f;
  2487. i2c_addr = RBIOS8(offset + 6);
  2488. } else if (rev == 2) {
  2489. thermal_controller = RBIOS8(offset + 4);
  2490. gpio = RBIOS8(offset + 5) & 0x3f;
  2491. i2c_addr = RBIOS8(offset + 6);
  2492. clk_bit = RBIOS8(offset + 0xa);
  2493. data_bit = RBIOS8(offset + 0xb);
  2494. }
  2495. if ((thermal_controller > 0) && (thermal_controller < 3)) {
  2496. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2497. thermal_controller_names[thermal_controller],
  2498. i2c_addr >> 1);
  2499. if (gpio == DDC_LCD) {
  2500. /* MM i2c */
  2501. i2c_bus.valid = true;
  2502. i2c_bus.hw_capable = true;
  2503. i2c_bus.mm_i2c = true;
  2504. i2c_bus.i2c_id = 0xa0;
  2505. } else if (gpio == DDC_GPIO)
  2506. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
  2507. else
  2508. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  2509. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2510. if (rdev->pm.i2c_bus) {
  2511. struct i2c_board_info info = { };
  2512. const char *name = thermal_controller_names[thermal_controller];
  2513. info.addr = i2c_addr >> 1;
  2514. strlcpy(info.type, name, sizeof(info.type));
  2515. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2516. }
  2517. }
  2518. } else {
  2519. /* boards with a thermal chip, but no overdrive table */
  2520. /* Asus 9600xt has an f75375 on the monid bus */
  2521. if ((dev->pdev->device == 0x4152) &&
  2522. (dev->pdev->subsystem_vendor == 0x1043) &&
  2523. (dev->pdev->subsystem_device == 0xc002)) {
  2524. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  2525. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2526. if (rdev->pm.i2c_bus) {
  2527. struct i2c_board_info info = { };
  2528. const char *name = "f75375";
  2529. info.addr = 0x28;
  2530. strlcpy(info.type, name, sizeof(info.type));
  2531. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2532. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2533. name, info.addr);
  2534. }
  2535. }
  2536. }
  2537. if (rdev->flags & RADEON_IS_MOBILITY) {
  2538. offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
  2539. if (offset) {
  2540. rev = RBIOS8(offset);
  2541. blocks = RBIOS8(offset + 0x2);
  2542. /* power mode 0 tends to be the only valid one */
  2543. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2544. rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
  2545. rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
  2546. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  2547. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  2548. goto default_mode;
  2549. rdev->pm.power_state[state_index].type =
  2550. POWER_STATE_TYPE_BATTERY;
  2551. misc = RBIOS16(offset + 0x5 + 0x0);
  2552. if (rev > 4)
  2553. misc2 = RBIOS16(offset + 0x5 + 0xe);
  2554. rdev->pm.power_state[state_index].misc = misc;
  2555. rdev->pm.power_state[state_index].misc2 = misc2;
  2556. if (misc & 0x4) {
  2557. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
  2558. if (misc & 0x8)
  2559. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2560. true;
  2561. else
  2562. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2563. false;
  2564. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
  2565. if (rev < 6) {
  2566. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2567. RBIOS16(offset + 0x5 + 0xb) * 4;
  2568. tmp = RBIOS8(offset + 0x5 + 0xd);
  2569. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2570. } else {
  2571. u8 entries = RBIOS8(offset + 0x5 + 0xb);
  2572. u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
  2573. if (entries && voltage_table_offset) {
  2574. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2575. RBIOS16(voltage_table_offset) * 4;
  2576. tmp = RBIOS8(voltage_table_offset + 0x2);
  2577. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2578. } else
  2579. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
  2580. }
  2581. switch ((misc2 & 0x700) >> 8) {
  2582. case 0:
  2583. default:
  2584. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
  2585. break;
  2586. case 1:
  2587. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
  2588. break;
  2589. case 2:
  2590. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
  2591. break;
  2592. case 3:
  2593. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
  2594. break;
  2595. case 4:
  2596. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
  2597. break;
  2598. }
  2599. } else
  2600. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2601. if (rev > 6)
  2602. rdev->pm.power_state[state_index].pcie_lanes =
  2603. RBIOS8(offset + 0x5 + 0x10);
  2604. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2605. state_index++;
  2606. } else {
  2607. /* XXX figure out some good default low power mode for mobility cards w/out power tables */
  2608. }
  2609. } else {
  2610. /* XXX figure out some good default low power mode for desktop cards */
  2611. }
  2612. default_mode:
  2613. /* add the default mode */
  2614. rdev->pm.power_state[state_index].type =
  2615. POWER_STATE_TYPE_DEFAULT;
  2616. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2617. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2618. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2619. rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
  2620. if ((state_index > 0) &&
  2621. (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
  2622. rdev->pm.power_state[state_index].clock_info[0].voltage =
  2623. rdev->pm.power_state[0].clock_info[0].voltage;
  2624. else
  2625. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2626. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2627. rdev->pm.power_state[state_index].flags = 0;
  2628. rdev->pm.default_power_state_index = state_index;
  2629. rdev->pm.num_power_states = state_index + 1;
  2630. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2631. rdev->pm.current_clock_mode_index = 0;
  2632. return;
  2633. pm_failed:
  2634. rdev->pm.default_power_state_index = state_index;
  2635. rdev->pm.num_power_states = 0;
  2636. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2637. rdev->pm.current_clock_mode_index = 0;
  2638. }
  2639. void radeon_external_tmds_setup(struct drm_encoder *encoder)
  2640. {
  2641. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2642. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2643. if (!tmds)
  2644. return;
  2645. switch (tmds->dvo_chip) {
  2646. case DVO_SIL164:
  2647. /* sil 164 */
  2648. radeon_i2c_put_byte(tmds->i2c_bus,
  2649. tmds->slave_addr,
  2650. 0x08, 0x30);
  2651. radeon_i2c_put_byte(tmds->i2c_bus,
  2652. tmds->slave_addr,
  2653. 0x09, 0x00);
  2654. radeon_i2c_put_byte(tmds->i2c_bus,
  2655. tmds->slave_addr,
  2656. 0x0a, 0x90);
  2657. radeon_i2c_put_byte(tmds->i2c_bus,
  2658. tmds->slave_addr,
  2659. 0x0c, 0x89);
  2660. radeon_i2c_put_byte(tmds->i2c_bus,
  2661. tmds->slave_addr,
  2662. 0x08, 0x3b);
  2663. break;
  2664. case DVO_SIL1178:
  2665. /* sil 1178 - untested */
  2666. /*
  2667. * 0x0f, 0x44
  2668. * 0x0f, 0x4c
  2669. * 0x0e, 0x01
  2670. * 0x0a, 0x80
  2671. * 0x09, 0x30
  2672. * 0x0c, 0xc9
  2673. * 0x0d, 0x70
  2674. * 0x08, 0x32
  2675. * 0x08, 0x33
  2676. */
  2677. break;
  2678. default:
  2679. break;
  2680. }
  2681. }
  2682. bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
  2683. {
  2684. struct drm_device *dev = encoder->dev;
  2685. struct radeon_device *rdev = dev->dev_private;
  2686. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2687. uint16_t offset;
  2688. uint8_t blocks, slave_addr, rev;
  2689. uint32_t index, id;
  2690. uint32_t reg, val, and_mask, or_mask;
  2691. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2692. if (!tmds)
  2693. return false;
  2694. if (rdev->flags & RADEON_IS_IGP) {
  2695. offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
  2696. rev = RBIOS8(offset);
  2697. if (offset) {
  2698. rev = RBIOS8(offset);
  2699. if (rev > 1) {
  2700. blocks = RBIOS8(offset + 3);
  2701. index = offset + 4;
  2702. while (blocks > 0) {
  2703. id = RBIOS16(index);
  2704. index += 2;
  2705. switch (id >> 13) {
  2706. case 0:
  2707. reg = (id & 0x1fff) * 4;
  2708. val = RBIOS32(index);
  2709. index += 4;
  2710. WREG32(reg, val);
  2711. break;
  2712. case 2:
  2713. reg = (id & 0x1fff) * 4;
  2714. and_mask = RBIOS32(index);
  2715. index += 4;
  2716. or_mask = RBIOS32(index);
  2717. index += 4;
  2718. val = RREG32(reg);
  2719. val = (val & and_mask) | or_mask;
  2720. WREG32(reg, val);
  2721. break;
  2722. case 3:
  2723. val = RBIOS16(index);
  2724. index += 2;
  2725. udelay(val);
  2726. break;
  2727. case 4:
  2728. val = RBIOS16(index);
  2729. index += 2;
  2730. mdelay(val);
  2731. break;
  2732. case 6:
  2733. slave_addr = id & 0xff;
  2734. slave_addr >>= 1; /* 7 bit addressing */
  2735. index++;
  2736. reg = RBIOS8(index);
  2737. index++;
  2738. val = RBIOS8(index);
  2739. index++;
  2740. radeon_i2c_put_byte(tmds->i2c_bus,
  2741. slave_addr,
  2742. reg, val);
  2743. break;
  2744. default:
  2745. DRM_ERROR("Unknown id %d\n", id >> 13);
  2746. break;
  2747. }
  2748. blocks--;
  2749. }
  2750. return true;
  2751. }
  2752. }
  2753. } else {
  2754. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2755. if (offset) {
  2756. index = offset + 10;
  2757. id = RBIOS16(index);
  2758. while (id != 0xffff) {
  2759. index += 2;
  2760. switch (id >> 13) {
  2761. case 0:
  2762. reg = (id & 0x1fff) * 4;
  2763. val = RBIOS32(index);
  2764. WREG32(reg, val);
  2765. break;
  2766. case 2:
  2767. reg = (id & 0x1fff) * 4;
  2768. and_mask = RBIOS32(index);
  2769. index += 4;
  2770. or_mask = RBIOS32(index);
  2771. index += 4;
  2772. val = RREG32(reg);
  2773. val = (val & and_mask) | or_mask;
  2774. WREG32(reg, val);
  2775. break;
  2776. case 4:
  2777. val = RBIOS16(index);
  2778. index += 2;
  2779. udelay(val);
  2780. break;
  2781. case 5:
  2782. reg = id & 0x1fff;
  2783. and_mask = RBIOS32(index);
  2784. index += 4;
  2785. or_mask = RBIOS32(index);
  2786. index += 4;
  2787. val = RREG32_PLL(reg);
  2788. val = (val & and_mask) | or_mask;
  2789. WREG32_PLL(reg, val);
  2790. break;
  2791. case 6:
  2792. reg = id & 0x1fff;
  2793. val = RBIOS8(index);
  2794. index += 1;
  2795. radeon_i2c_put_byte(tmds->i2c_bus,
  2796. tmds->slave_addr,
  2797. reg, val);
  2798. break;
  2799. default:
  2800. DRM_ERROR("Unknown id %d\n", id >> 13);
  2801. break;
  2802. }
  2803. id = RBIOS16(index);
  2804. }
  2805. return true;
  2806. }
  2807. }
  2808. return false;
  2809. }
  2810. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  2811. {
  2812. struct radeon_device *rdev = dev->dev_private;
  2813. if (offset) {
  2814. while (RBIOS16(offset)) {
  2815. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  2816. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  2817. uint32_t val, and_mask, or_mask;
  2818. uint32_t tmp;
  2819. offset += 2;
  2820. switch (cmd) {
  2821. case 0:
  2822. val = RBIOS32(offset);
  2823. offset += 4;
  2824. WREG32(addr, val);
  2825. break;
  2826. case 1:
  2827. val = RBIOS32(offset);
  2828. offset += 4;
  2829. WREG32(addr, val);
  2830. break;
  2831. case 2:
  2832. and_mask = RBIOS32(offset);
  2833. offset += 4;
  2834. or_mask = RBIOS32(offset);
  2835. offset += 4;
  2836. tmp = RREG32(addr);
  2837. tmp &= and_mask;
  2838. tmp |= or_mask;
  2839. WREG32(addr, tmp);
  2840. break;
  2841. case 3:
  2842. and_mask = RBIOS32(offset);
  2843. offset += 4;
  2844. or_mask = RBIOS32(offset);
  2845. offset += 4;
  2846. tmp = RREG32(addr);
  2847. tmp &= and_mask;
  2848. tmp |= or_mask;
  2849. WREG32(addr, tmp);
  2850. break;
  2851. case 4:
  2852. val = RBIOS16(offset);
  2853. offset += 2;
  2854. udelay(val);
  2855. break;
  2856. case 5:
  2857. val = RBIOS16(offset);
  2858. offset += 2;
  2859. switch (addr) {
  2860. case 8:
  2861. while (val--) {
  2862. if (!
  2863. (RREG32_PLL
  2864. (RADEON_CLK_PWRMGT_CNTL) &
  2865. RADEON_MC_BUSY))
  2866. break;
  2867. }
  2868. break;
  2869. case 9:
  2870. while (val--) {
  2871. if ((RREG32(RADEON_MC_STATUS) &
  2872. RADEON_MC_IDLE))
  2873. break;
  2874. }
  2875. break;
  2876. default:
  2877. break;
  2878. }
  2879. break;
  2880. default:
  2881. break;
  2882. }
  2883. }
  2884. }
  2885. }
  2886. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  2887. {
  2888. struct radeon_device *rdev = dev->dev_private;
  2889. if (offset) {
  2890. while (RBIOS8(offset)) {
  2891. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  2892. uint8_t addr = (RBIOS8(offset) & 0x3f);
  2893. uint32_t val, shift, tmp;
  2894. uint32_t and_mask, or_mask;
  2895. offset++;
  2896. switch (cmd) {
  2897. case 0:
  2898. val = RBIOS32(offset);
  2899. offset += 4;
  2900. WREG32_PLL(addr, val);
  2901. break;
  2902. case 1:
  2903. shift = RBIOS8(offset) * 8;
  2904. offset++;
  2905. and_mask = RBIOS8(offset) << shift;
  2906. and_mask |= ~(0xff << shift);
  2907. offset++;
  2908. or_mask = RBIOS8(offset) << shift;
  2909. offset++;
  2910. tmp = RREG32_PLL(addr);
  2911. tmp &= and_mask;
  2912. tmp |= or_mask;
  2913. WREG32_PLL(addr, tmp);
  2914. break;
  2915. case 2:
  2916. case 3:
  2917. tmp = 1000;
  2918. switch (addr) {
  2919. case 1:
  2920. udelay(150);
  2921. break;
  2922. case 2:
  2923. mdelay(1);
  2924. break;
  2925. case 3:
  2926. while (tmp--) {
  2927. if (!
  2928. (RREG32_PLL
  2929. (RADEON_CLK_PWRMGT_CNTL) &
  2930. RADEON_MC_BUSY))
  2931. break;
  2932. }
  2933. break;
  2934. case 4:
  2935. while (tmp--) {
  2936. if (RREG32_PLL
  2937. (RADEON_CLK_PWRMGT_CNTL) &
  2938. RADEON_DLL_READY)
  2939. break;
  2940. }
  2941. break;
  2942. case 5:
  2943. tmp =
  2944. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  2945. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  2946. #if 0
  2947. uint32_t mclk_cntl =
  2948. RREG32_PLL
  2949. (RADEON_MCLK_CNTL);
  2950. mclk_cntl &= 0xffff0000;
  2951. /*mclk_cntl |= 0x00001111;*//* ??? */
  2952. WREG32_PLL(RADEON_MCLK_CNTL,
  2953. mclk_cntl);
  2954. mdelay(10);
  2955. #endif
  2956. WREG32_PLL
  2957. (RADEON_CLK_PWRMGT_CNTL,
  2958. tmp &
  2959. ~RADEON_CG_NO1_DEBUG_0);
  2960. mdelay(10);
  2961. }
  2962. break;
  2963. default:
  2964. break;
  2965. }
  2966. break;
  2967. default:
  2968. break;
  2969. }
  2970. }
  2971. }
  2972. }
  2973. static void combios_parse_ram_reset_table(struct drm_device *dev,
  2974. uint16_t offset)
  2975. {
  2976. struct radeon_device *rdev = dev->dev_private;
  2977. uint32_t tmp;
  2978. if (offset) {
  2979. uint8_t val = RBIOS8(offset);
  2980. while (val != 0xff) {
  2981. offset++;
  2982. if (val == 0x0f) {
  2983. uint32_t channel_complete_mask;
  2984. if (ASIC_IS_R300(rdev))
  2985. channel_complete_mask =
  2986. R300_MEM_PWRUP_COMPLETE;
  2987. else
  2988. channel_complete_mask =
  2989. RADEON_MEM_PWRUP_COMPLETE;
  2990. tmp = 20000;
  2991. while (tmp--) {
  2992. if ((RREG32(RADEON_MEM_STR_CNTL) &
  2993. channel_complete_mask) ==
  2994. channel_complete_mask)
  2995. break;
  2996. }
  2997. } else {
  2998. uint32_t or_mask = RBIOS16(offset);
  2999. offset += 2;
  3000. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  3001. tmp &= RADEON_SDRAM_MODE_MASK;
  3002. tmp |= or_mask;
  3003. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  3004. or_mask = val << 24;
  3005. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  3006. tmp &= RADEON_B3MEM_RESET_MASK;
  3007. tmp |= or_mask;
  3008. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  3009. }
  3010. val = RBIOS8(offset);
  3011. }
  3012. }
  3013. }
  3014. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  3015. int mem_addr_mapping)
  3016. {
  3017. struct radeon_device *rdev = dev->dev_private;
  3018. uint32_t mem_cntl;
  3019. uint32_t mem_size;
  3020. uint32_t addr = 0;
  3021. mem_cntl = RREG32(RADEON_MEM_CNTL);
  3022. if (mem_cntl & RV100_HALF_MODE)
  3023. ram /= 2;
  3024. mem_size = ram;
  3025. mem_cntl &= ~(0xff << 8);
  3026. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  3027. WREG32(RADEON_MEM_CNTL, mem_cntl);
  3028. RREG32(RADEON_MEM_CNTL);
  3029. /* sdram reset ? */
  3030. /* something like this???? */
  3031. while (ram--) {
  3032. addr = ram * 1024 * 1024;
  3033. /* write to each page */
  3034. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  3035. WREG32(RADEON_MM_DATA, 0xdeadbeef);
  3036. /* read back and verify */
  3037. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  3038. if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
  3039. return 0;
  3040. }
  3041. return mem_size;
  3042. }
  3043. static void combios_write_ram_size(struct drm_device *dev)
  3044. {
  3045. struct radeon_device *rdev = dev->dev_private;
  3046. uint8_t rev;
  3047. uint16_t offset;
  3048. uint32_t mem_size = 0;
  3049. uint32_t mem_cntl = 0;
  3050. /* should do something smarter here I guess... */
  3051. if (rdev->flags & RADEON_IS_IGP)
  3052. return;
  3053. /* first check detected mem table */
  3054. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  3055. if (offset) {
  3056. rev = RBIOS8(offset);
  3057. if (rev < 3) {
  3058. mem_cntl = RBIOS32(offset + 1);
  3059. mem_size = RBIOS16(offset + 5);
  3060. if ((rdev->family < CHIP_R200) &&
  3061. !ASIC_IS_RN50(rdev))
  3062. WREG32(RADEON_MEM_CNTL, mem_cntl);
  3063. }
  3064. }
  3065. if (!mem_size) {
  3066. offset =
  3067. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  3068. if (offset) {
  3069. rev = RBIOS8(offset - 1);
  3070. if (rev < 1) {
  3071. if ((rdev->family < CHIP_R200)
  3072. && !ASIC_IS_RN50(rdev)) {
  3073. int ram = 0;
  3074. int mem_addr_mapping = 0;
  3075. while (RBIOS8(offset)) {
  3076. ram = RBIOS8(offset);
  3077. mem_addr_mapping =
  3078. RBIOS8(offset + 1);
  3079. if (mem_addr_mapping != 0x25)
  3080. ram *= 2;
  3081. mem_size =
  3082. combios_detect_ram(dev, ram,
  3083. mem_addr_mapping);
  3084. if (mem_size)
  3085. break;
  3086. offset += 2;
  3087. }
  3088. } else
  3089. mem_size = RBIOS8(offset);
  3090. } else {
  3091. mem_size = RBIOS8(offset);
  3092. mem_size *= 2; /* convert to MB */
  3093. }
  3094. }
  3095. }
  3096. mem_size *= (1024 * 1024); /* convert to bytes */
  3097. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  3098. }
  3099. void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
  3100. {
  3101. uint16_t dyn_clk_info =
  3102. combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3103. if (dyn_clk_info)
  3104. combios_parse_pll_table(dev, dyn_clk_info);
  3105. }
  3106. void radeon_combios_asic_init(struct drm_device *dev)
  3107. {
  3108. struct radeon_device *rdev = dev->dev_private;
  3109. uint16_t table;
  3110. /* port hardcoded mac stuff from radeonfb */
  3111. if (rdev->bios == NULL)
  3112. return;
  3113. /* ASIC INIT 1 */
  3114. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  3115. if (table)
  3116. combios_parse_mmio_table(dev, table);
  3117. /* PLL INIT */
  3118. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  3119. if (table)
  3120. combios_parse_pll_table(dev, table);
  3121. /* ASIC INIT 2 */
  3122. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  3123. if (table)
  3124. combios_parse_mmio_table(dev, table);
  3125. if (!(rdev->flags & RADEON_IS_IGP)) {
  3126. /* ASIC INIT 4 */
  3127. table =
  3128. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  3129. if (table)
  3130. combios_parse_mmio_table(dev, table);
  3131. /* RAM RESET */
  3132. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  3133. if (table)
  3134. combios_parse_ram_reset_table(dev, table);
  3135. /* ASIC INIT 3 */
  3136. table =
  3137. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  3138. if (table)
  3139. combios_parse_mmio_table(dev, table);
  3140. /* write CONFIG_MEMSIZE */
  3141. combios_write_ram_size(dev);
  3142. }
  3143. /* quirk for rs4xx HP nx6125 laptop to make it resume
  3144. * - it hangs on resume inside the dynclk 1 table.
  3145. */
  3146. if (rdev->family == CHIP_RS480 &&
  3147. rdev->pdev->subsystem_vendor == 0x103c &&
  3148. rdev->pdev->subsystem_device == 0x308b)
  3149. return;
  3150. /* quirk for rs4xx HP dv5000 laptop to make it resume
  3151. * - it hangs on resume inside the dynclk 1 table.
  3152. */
  3153. if (rdev->family == CHIP_RS480 &&
  3154. rdev->pdev->subsystem_vendor == 0x103c &&
  3155. rdev->pdev->subsystem_device == 0x30a4)
  3156. return;
  3157. /* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
  3158. * - it hangs on resume inside the dynclk 1 table.
  3159. */
  3160. if (rdev->family == CHIP_RS480 &&
  3161. rdev->pdev->subsystem_vendor == 0x103c &&
  3162. rdev->pdev->subsystem_device == 0x30ae)
  3163. return;
  3164. /* DYN CLK 1 */
  3165. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3166. if (table)
  3167. combios_parse_pll_table(dev, table);
  3168. }
  3169. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  3170. {
  3171. struct radeon_device *rdev = dev->dev_private;
  3172. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  3173. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3174. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3175. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  3176. /* let the bios control the backlight */
  3177. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  3178. /* tell the bios not to handle mode switching */
  3179. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  3180. RADEON_ACC_MODE_CHANGE);
  3181. /* tell the bios a driver is loaded */
  3182. bios_7_scratch |= RADEON_DRV_LOADED;
  3183. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3184. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3185. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  3186. }
  3187. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  3188. {
  3189. struct drm_device *dev = encoder->dev;
  3190. struct radeon_device *rdev = dev->dev_private;
  3191. uint32_t bios_6_scratch;
  3192. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3193. if (lock)
  3194. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  3195. else
  3196. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  3197. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3198. }
  3199. void
  3200. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  3201. struct drm_encoder *encoder,
  3202. bool connected)
  3203. {
  3204. struct drm_device *dev = connector->dev;
  3205. struct radeon_device *rdev = dev->dev_private;
  3206. struct radeon_connector *radeon_connector =
  3207. to_radeon_connector(connector);
  3208. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3209. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  3210. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3211. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3212. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3213. if (connected) {
  3214. DRM_DEBUG_KMS("TV1 connected\n");
  3215. /* fix me */
  3216. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  3217. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  3218. bios_5_scratch |= RADEON_TV1_ON;
  3219. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  3220. } else {
  3221. DRM_DEBUG_KMS("TV1 disconnected\n");
  3222. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  3223. bios_5_scratch &= ~RADEON_TV1_ON;
  3224. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  3225. }
  3226. }
  3227. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3228. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3229. if (connected) {
  3230. DRM_DEBUG_KMS("LCD1 connected\n");
  3231. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  3232. bios_5_scratch |= RADEON_LCD1_ON;
  3233. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  3234. } else {
  3235. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3236. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  3237. bios_5_scratch &= ~RADEON_LCD1_ON;
  3238. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  3239. }
  3240. }
  3241. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3242. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3243. if (connected) {
  3244. DRM_DEBUG_KMS("CRT1 connected\n");
  3245. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  3246. bios_5_scratch |= RADEON_CRT1_ON;
  3247. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  3248. } else {
  3249. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3250. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  3251. bios_5_scratch &= ~RADEON_CRT1_ON;
  3252. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  3253. }
  3254. }
  3255. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3256. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3257. if (connected) {
  3258. DRM_DEBUG_KMS("CRT2 connected\n");
  3259. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  3260. bios_5_scratch |= RADEON_CRT2_ON;
  3261. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  3262. } else {
  3263. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3264. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  3265. bios_5_scratch &= ~RADEON_CRT2_ON;
  3266. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  3267. }
  3268. }
  3269. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3270. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3271. if (connected) {
  3272. DRM_DEBUG_KMS("DFP1 connected\n");
  3273. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  3274. bios_5_scratch |= RADEON_DFP1_ON;
  3275. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  3276. } else {
  3277. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3278. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  3279. bios_5_scratch &= ~RADEON_DFP1_ON;
  3280. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  3281. }
  3282. }
  3283. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3284. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3285. if (connected) {
  3286. DRM_DEBUG_KMS("DFP2 connected\n");
  3287. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  3288. bios_5_scratch |= RADEON_DFP2_ON;
  3289. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  3290. } else {
  3291. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3292. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  3293. bios_5_scratch &= ~RADEON_DFP2_ON;
  3294. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  3295. }
  3296. }
  3297. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  3298. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3299. }
  3300. void
  3301. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3302. {
  3303. struct drm_device *dev = encoder->dev;
  3304. struct radeon_device *rdev = dev->dev_private;
  3305. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3306. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3307. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3308. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  3309. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  3310. }
  3311. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3312. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  3313. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  3314. }
  3315. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3316. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  3317. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  3318. }
  3319. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3320. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  3321. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  3322. }
  3323. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3324. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  3325. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  3326. }
  3327. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3328. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  3329. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  3330. }
  3331. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3332. }
  3333. void
  3334. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3335. {
  3336. struct drm_device *dev = encoder->dev;
  3337. struct radeon_device *rdev = dev->dev_private;
  3338. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3339. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3340. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  3341. if (on)
  3342. bios_6_scratch |= RADEON_TV_DPMS_ON;
  3343. else
  3344. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  3345. }
  3346. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3347. if (on)
  3348. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  3349. else
  3350. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  3351. }
  3352. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3353. if (on)
  3354. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  3355. else
  3356. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  3357. }
  3358. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  3359. if (on)
  3360. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  3361. else
  3362. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  3363. }
  3364. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3365. }