radeon_combios.c 93 KB

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