radeon_combios.c 102 KB

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