radeon_combios.c 73 KB

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