radeon_combios.c 102 KB

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