radeon_combios.c 91 KB

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