radeon_combios.c 69 KB

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