radeon_combios.c 84 KB

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