radeon_combios.c 91 KB

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