radeon_combios.c 91 KB

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