radeon_combios.c 102 KB

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