radeon_combios.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481
  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. } else {
  729. DRM_INFO("No TV DAC info found in BIOS\n");
  730. return radeon_legacy_get_tv_dac_info_from_table(rdev);
  731. }
  732. }
  733. return tv_dac;
  734. }
  735. static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
  736. radeon_device
  737. *rdev)
  738. {
  739. struct radeon_encoder_lvds *lvds = NULL;
  740. uint32_t fp_vert_stretch, fp_horz_stretch;
  741. uint32_t ppll_div_sel, ppll_val;
  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. if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
  748. lvds->native_mode.panel_yres =
  749. ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
  750. RADEON_VERT_PANEL_SHIFT) + 1;
  751. else
  752. lvds->native_mode.panel_yres =
  753. (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
  754. if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
  755. lvds->native_mode.panel_xres =
  756. (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
  757. RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
  758. else
  759. lvds->native_mode.panel_xres =
  760. ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
  761. if ((lvds->native_mode.panel_xres < 640) ||
  762. (lvds->native_mode.panel_yres < 480)) {
  763. lvds->native_mode.panel_xres = 640;
  764. lvds->native_mode.panel_yres = 480;
  765. }
  766. ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
  767. ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
  768. if ((ppll_val & 0x000707ff) == 0x1bb)
  769. lvds->use_bios_dividers = false;
  770. else {
  771. lvds->panel_ref_divider =
  772. RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  773. lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
  774. lvds->panel_fb_divider = ppll_val & 0x7ff;
  775. if ((lvds->panel_ref_divider != 0) &&
  776. (lvds->panel_fb_divider > 3))
  777. lvds->use_bios_dividers = true;
  778. }
  779. lvds->panel_vcc_delay = 200;
  780. DRM_INFO("Panel info derived from registers\n");
  781. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.panel_xres,
  782. lvds->native_mode.panel_yres);
  783. return lvds;
  784. }
  785. struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
  786. *encoder)
  787. {
  788. struct drm_device *dev = encoder->base.dev;
  789. struct radeon_device *rdev = dev->dev_private;
  790. uint16_t lcd_info;
  791. uint32_t panel_setup;
  792. char stmp[30];
  793. int tmp, i;
  794. struct radeon_encoder_lvds *lvds = NULL;
  795. if (rdev->bios == NULL)
  796. return radeon_legacy_get_lvds_info_from_regs(rdev);
  797. lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  798. if (lcd_info) {
  799. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  800. if (!lvds)
  801. return NULL;
  802. for (i = 0; i < 24; i++)
  803. stmp[i] = RBIOS8(lcd_info + i + 1);
  804. stmp[24] = 0;
  805. DRM_INFO("Panel ID String: %s\n", stmp);
  806. lvds->native_mode.panel_xres = RBIOS16(lcd_info + 0x19);
  807. lvds->native_mode.panel_yres = RBIOS16(lcd_info + 0x1b);
  808. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.panel_xres,
  809. lvds->native_mode.panel_yres);
  810. lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
  811. if (lvds->panel_vcc_delay > 2000 || lvds->panel_vcc_delay < 0)
  812. lvds->panel_vcc_delay = 2000;
  813. lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
  814. lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
  815. lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
  816. lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
  817. lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
  818. lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
  819. if ((lvds->panel_ref_divider != 0) &&
  820. (lvds->panel_fb_divider > 3))
  821. lvds->use_bios_dividers = true;
  822. panel_setup = RBIOS32(lcd_info + 0x39);
  823. lvds->lvds_gen_cntl = 0xff00;
  824. if (panel_setup & 0x1)
  825. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
  826. if ((panel_setup >> 4) & 0x1)
  827. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
  828. switch ((panel_setup >> 8) & 0x7) {
  829. case 0:
  830. lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
  831. break;
  832. case 1:
  833. lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
  834. break;
  835. case 2:
  836. lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
  837. break;
  838. default:
  839. break;
  840. }
  841. if ((panel_setup >> 16) & 0x1)
  842. lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
  843. if ((panel_setup >> 17) & 0x1)
  844. lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
  845. if ((panel_setup >> 18) & 0x1)
  846. lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
  847. if ((panel_setup >> 23) & 0x1)
  848. lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
  849. lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
  850. for (i = 0; i < 32; i++) {
  851. tmp = RBIOS16(lcd_info + 64 + i * 2);
  852. if (tmp == 0)
  853. break;
  854. if ((RBIOS16(tmp) == lvds->native_mode.panel_xres) &&
  855. (RBIOS16(tmp + 2) ==
  856. lvds->native_mode.panel_yres)) {
  857. lvds->native_mode.hblank =
  858. (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
  859. lvds->native_mode.hoverplus =
  860. (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) -
  861. 1) * 8;
  862. lvds->native_mode.hsync_width =
  863. RBIOS8(tmp + 23) * 8;
  864. lvds->native_mode.vblank = (RBIOS16(tmp + 24) -
  865. RBIOS16(tmp + 26));
  866. lvds->native_mode.voverplus =
  867. ((RBIOS16(tmp + 28) & 0x7ff) -
  868. RBIOS16(tmp + 26));
  869. lvds->native_mode.vsync_width =
  870. ((RBIOS16(tmp + 28) & 0xf800) >> 11);
  871. lvds->native_mode.dotclock =
  872. RBIOS16(tmp + 9) * 10;
  873. lvds->native_mode.flags = 0;
  874. }
  875. }
  876. encoder->native_mode = lvds->native_mode;
  877. } else {
  878. DRM_INFO("No panel info found in BIOS\n");
  879. return radeon_legacy_get_lvds_info_from_regs(rdev);
  880. }
  881. return lvds;
  882. }
  883. static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
  884. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
  885. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
  886. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
  887. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
  888. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
  889. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
  890. {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
  891. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
  892. {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
  893. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
  894. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
  895. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
  896. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
  897. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
  898. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
  899. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
  900. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RS400 */
  901. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RS480 */
  902. };
  903. static struct radeon_encoder_int_tmds
  904. *radeon_legacy_get_tmds_info_from_table(struct radeon_device *rdev)
  905. {
  906. int i;
  907. struct radeon_encoder_int_tmds *tmds = NULL;
  908. tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  909. if (!tmds)
  910. return NULL;
  911. for (i = 0; i < 4; i++) {
  912. tmds->tmds_pll[i].value =
  913. default_tmds_pll[rdev->family][i].value;
  914. tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
  915. }
  916. return tmds;
  917. }
  918. struct radeon_encoder_int_tmds *radeon_combios_get_tmds_info(struct
  919. radeon_encoder
  920. *encoder)
  921. {
  922. struct drm_device *dev = encoder->base.dev;
  923. struct radeon_device *rdev = dev->dev_private;
  924. uint16_t tmds_info;
  925. int i, n;
  926. uint8_t ver;
  927. struct radeon_encoder_int_tmds *tmds = NULL;
  928. if (rdev->bios == NULL)
  929. return radeon_legacy_get_tmds_info_from_table(rdev);
  930. tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  931. if (tmds_info) {
  932. tmds =
  933. kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  934. if (!tmds)
  935. return NULL;
  936. ver = RBIOS8(tmds_info);
  937. DRM_INFO("DFP table revision: %d\n", ver);
  938. if (ver == 3) {
  939. n = RBIOS8(tmds_info + 5) + 1;
  940. if (n > 4)
  941. n = 4;
  942. for (i = 0; i < n; i++) {
  943. tmds->tmds_pll[i].value =
  944. RBIOS32(tmds_info + i * 10 + 0x08);
  945. tmds->tmds_pll[i].freq =
  946. RBIOS16(tmds_info + i * 10 + 0x10);
  947. DRM_DEBUG("TMDS PLL From COMBIOS %u %x\n",
  948. tmds->tmds_pll[i].freq,
  949. tmds->tmds_pll[i].value);
  950. }
  951. } else if (ver == 4) {
  952. int stride = 0;
  953. n = RBIOS8(tmds_info + 5) + 1;
  954. if (n > 4)
  955. n = 4;
  956. for (i = 0; i < n; i++) {
  957. tmds->tmds_pll[i].value =
  958. RBIOS32(tmds_info + stride + 0x08);
  959. tmds->tmds_pll[i].freq =
  960. RBIOS16(tmds_info + stride + 0x10);
  961. if (i == 0)
  962. stride += 10;
  963. else
  964. stride += 6;
  965. DRM_DEBUG("TMDS PLL From COMBIOS %u %x\n",
  966. tmds->tmds_pll[i].freq,
  967. tmds->tmds_pll[i].value);
  968. }
  969. }
  970. } else
  971. DRM_INFO("No TMDS info found in BIOS\n");
  972. return tmds;
  973. }
  974. void radeon_combios_get_ext_tmds_info(struct radeon_encoder *encoder)
  975. {
  976. struct drm_device *dev = encoder->base.dev;
  977. struct radeon_device *rdev = dev->dev_private;
  978. uint16_t ext_tmds_info;
  979. uint8_t ver;
  980. if (rdev->bios == NULL)
  981. return;
  982. ext_tmds_info =
  983. combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  984. if (ext_tmds_info) {
  985. ver = RBIOS8(ext_tmds_info);
  986. DRM_INFO("External TMDS Table revision: %d\n", ver);
  987. // TODO
  988. }
  989. }
  990. bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
  991. {
  992. struct radeon_device *rdev = dev->dev_private;
  993. struct radeon_i2c_bus_rec ddc_i2c;
  994. rdev->mode_info.connector_table = radeon_connector_table;
  995. if (rdev->mode_info.connector_table == CT_NONE) {
  996. #ifdef CONFIG_PPC_PMAC
  997. if (machine_is_compatible("PowerBook3,3")) {
  998. /* powerbook with VGA */
  999. rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
  1000. } else if (machine_is_compatible("PowerBook3,4") ||
  1001. machine_is_compatible("PowerBook3,5")) {
  1002. /* powerbook with internal tmds */
  1003. rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
  1004. } else if (machine_is_compatible("PowerBook5,1") ||
  1005. machine_is_compatible("PowerBook5,2") ||
  1006. machine_is_compatible("PowerBook5,3") ||
  1007. machine_is_compatible("PowerBook5,4") ||
  1008. machine_is_compatible("PowerBook5,5")) {
  1009. /* powerbook with external single link tmds (sil164) */
  1010. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1011. } else if (machine_is_compatible("PowerBook5,6")) {
  1012. /* powerbook with external dual or single link tmds */
  1013. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1014. } else if (machine_is_compatible("PowerBook5,7") ||
  1015. machine_is_compatible("PowerBook5,8") ||
  1016. machine_is_compatible("PowerBook5,9")) {
  1017. /* PowerBook6,2 ? */
  1018. /* powerbook with external dual link tmds (sil1178?) */
  1019. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1020. } else if (machine_is_compatible("PowerBook4,1") ||
  1021. machine_is_compatible("PowerBook4,2") ||
  1022. machine_is_compatible("PowerBook4,3") ||
  1023. machine_is_compatible("PowerBook6,3") ||
  1024. machine_is_compatible("PowerBook6,5") ||
  1025. machine_is_compatible("PowerBook6,7")) {
  1026. /* ibook */
  1027. rdev->mode_info.connector_table = CT_IBOOK;
  1028. } else if (machine_is_compatible("PowerMac4,4")) {
  1029. /* emac */
  1030. rdev->mode_info.connector_table = CT_EMAC;
  1031. } else if (machine_is_compatible("PowerMac10,1")) {
  1032. /* mini with internal tmds */
  1033. rdev->mode_info.connector_table = CT_MINI_INTERNAL;
  1034. } else if (machine_is_compatible("PowerMac10,2")) {
  1035. /* mini with external tmds */
  1036. rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
  1037. } else if (machine_is_compatible("PowerMac12,1")) {
  1038. /* PowerMac8,1 ? */
  1039. /* imac g5 isight */
  1040. rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
  1041. } else
  1042. #endif /* CONFIG_PPC_PMAC */
  1043. rdev->mode_info.connector_table = CT_GENERIC;
  1044. }
  1045. switch (rdev->mode_info.connector_table) {
  1046. case CT_GENERIC:
  1047. DRM_INFO("Connector Table: %d (generic)\n",
  1048. rdev->mode_info.connector_table);
  1049. /* these are the most common settings */
  1050. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1051. /* VGA - primary dac */
  1052. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1053. radeon_add_legacy_encoder(dev,
  1054. radeon_get_encoder_id(dev,
  1055. ATOM_DEVICE_CRT1_SUPPORT,
  1056. 1),
  1057. ATOM_DEVICE_CRT1_SUPPORT);
  1058. radeon_add_legacy_connector(dev, 0,
  1059. ATOM_DEVICE_CRT1_SUPPORT,
  1060. DRM_MODE_CONNECTOR_VGA,
  1061. &ddc_i2c);
  1062. } else if (rdev->flags & RADEON_IS_MOBILITY) {
  1063. /* LVDS */
  1064. ddc_i2c = combios_setup_i2c_bus(RADEON_LCD_GPIO_MASK);
  1065. radeon_add_legacy_encoder(dev,
  1066. radeon_get_encoder_id(dev,
  1067. ATOM_DEVICE_LCD1_SUPPORT,
  1068. 0),
  1069. ATOM_DEVICE_LCD1_SUPPORT);
  1070. radeon_add_legacy_connector(dev, 0,
  1071. ATOM_DEVICE_LCD1_SUPPORT,
  1072. DRM_MODE_CONNECTOR_LVDS,
  1073. &ddc_i2c);
  1074. /* VGA - primary dac */
  1075. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1076. radeon_add_legacy_encoder(dev,
  1077. radeon_get_encoder_id(dev,
  1078. ATOM_DEVICE_CRT1_SUPPORT,
  1079. 1),
  1080. ATOM_DEVICE_CRT1_SUPPORT);
  1081. radeon_add_legacy_connector(dev, 1,
  1082. ATOM_DEVICE_CRT1_SUPPORT,
  1083. DRM_MODE_CONNECTOR_VGA,
  1084. &ddc_i2c);
  1085. } else {
  1086. /* DVI-I - tv dac, int tmds */
  1087. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1088. radeon_add_legacy_encoder(dev,
  1089. radeon_get_encoder_id(dev,
  1090. ATOM_DEVICE_DFP1_SUPPORT,
  1091. 0),
  1092. ATOM_DEVICE_DFP1_SUPPORT);
  1093. radeon_add_legacy_encoder(dev,
  1094. radeon_get_encoder_id(dev,
  1095. ATOM_DEVICE_CRT2_SUPPORT,
  1096. 2),
  1097. ATOM_DEVICE_CRT2_SUPPORT);
  1098. radeon_add_legacy_connector(dev, 0,
  1099. ATOM_DEVICE_DFP1_SUPPORT |
  1100. ATOM_DEVICE_CRT2_SUPPORT,
  1101. DRM_MODE_CONNECTOR_DVII,
  1102. &ddc_i2c);
  1103. /* VGA - primary dac */
  1104. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1105. radeon_add_legacy_encoder(dev,
  1106. radeon_get_encoder_id(dev,
  1107. ATOM_DEVICE_CRT1_SUPPORT,
  1108. 1),
  1109. ATOM_DEVICE_CRT1_SUPPORT);
  1110. radeon_add_legacy_connector(dev, 1,
  1111. ATOM_DEVICE_CRT1_SUPPORT,
  1112. DRM_MODE_CONNECTOR_VGA,
  1113. &ddc_i2c);
  1114. }
  1115. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1116. /* TV - tv dac */
  1117. radeon_add_legacy_encoder(dev,
  1118. radeon_get_encoder_id(dev,
  1119. ATOM_DEVICE_TV1_SUPPORT,
  1120. 2),
  1121. ATOM_DEVICE_TV1_SUPPORT);
  1122. radeon_add_legacy_connector(dev, 2,
  1123. ATOM_DEVICE_TV1_SUPPORT,
  1124. DRM_MODE_CONNECTOR_SVIDEO,
  1125. &ddc_i2c);
  1126. }
  1127. break;
  1128. case CT_IBOOK:
  1129. DRM_INFO("Connector Table: %d (ibook)\n",
  1130. rdev->mode_info.connector_table);
  1131. /* LVDS */
  1132. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1133. radeon_add_legacy_encoder(dev,
  1134. radeon_get_encoder_id(dev,
  1135. ATOM_DEVICE_LCD1_SUPPORT,
  1136. 0),
  1137. ATOM_DEVICE_LCD1_SUPPORT);
  1138. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1139. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c);
  1140. /* VGA - TV DAC */
  1141. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1142. radeon_add_legacy_encoder(dev,
  1143. radeon_get_encoder_id(dev,
  1144. ATOM_DEVICE_CRT2_SUPPORT,
  1145. 2),
  1146. ATOM_DEVICE_CRT2_SUPPORT);
  1147. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1148. DRM_MODE_CONNECTOR_VGA, &ddc_i2c);
  1149. /* TV - TV DAC */
  1150. radeon_add_legacy_encoder(dev,
  1151. radeon_get_encoder_id(dev,
  1152. ATOM_DEVICE_TV1_SUPPORT,
  1153. 2),
  1154. ATOM_DEVICE_TV1_SUPPORT);
  1155. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1156. DRM_MODE_CONNECTOR_SVIDEO,
  1157. &ddc_i2c);
  1158. break;
  1159. case CT_POWERBOOK_EXTERNAL:
  1160. DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
  1161. rdev->mode_info.connector_table);
  1162. /* LVDS */
  1163. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1164. radeon_add_legacy_encoder(dev,
  1165. radeon_get_encoder_id(dev,
  1166. ATOM_DEVICE_LCD1_SUPPORT,
  1167. 0),
  1168. ATOM_DEVICE_LCD1_SUPPORT);
  1169. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1170. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c);
  1171. /* DVI-I - primary dac, ext tmds */
  1172. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1173. radeon_add_legacy_encoder(dev,
  1174. radeon_get_encoder_id(dev,
  1175. ATOM_DEVICE_DFP2_SUPPORT,
  1176. 0),
  1177. ATOM_DEVICE_DFP2_SUPPORT);
  1178. radeon_add_legacy_encoder(dev,
  1179. radeon_get_encoder_id(dev,
  1180. ATOM_DEVICE_CRT1_SUPPORT,
  1181. 1),
  1182. ATOM_DEVICE_CRT1_SUPPORT);
  1183. radeon_add_legacy_connector(dev, 1,
  1184. ATOM_DEVICE_DFP2_SUPPORT |
  1185. ATOM_DEVICE_CRT1_SUPPORT,
  1186. DRM_MODE_CONNECTOR_DVII, &ddc_i2c);
  1187. /* TV - TV DAC */
  1188. radeon_add_legacy_encoder(dev,
  1189. radeon_get_encoder_id(dev,
  1190. ATOM_DEVICE_TV1_SUPPORT,
  1191. 2),
  1192. ATOM_DEVICE_TV1_SUPPORT);
  1193. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1194. DRM_MODE_CONNECTOR_SVIDEO,
  1195. &ddc_i2c);
  1196. break;
  1197. case CT_POWERBOOK_INTERNAL:
  1198. DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
  1199. rdev->mode_info.connector_table);
  1200. /* LVDS */
  1201. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1202. radeon_add_legacy_encoder(dev,
  1203. radeon_get_encoder_id(dev,
  1204. ATOM_DEVICE_LCD1_SUPPORT,
  1205. 0),
  1206. ATOM_DEVICE_LCD1_SUPPORT);
  1207. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1208. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c);
  1209. /* DVI-I - primary dac, int tmds */
  1210. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1211. radeon_add_legacy_encoder(dev,
  1212. radeon_get_encoder_id(dev,
  1213. ATOM_DEVICE_DFP1_SUPPORT,
  1214. 0),
  1215. ATOM_DEVICE_DFP1_SUPPORT);
  1216. radeon_add_legacy_encoder(dev,
  1217. radeon_get_encoder_id(dev,
  1218. ATOM_DEVICE_CRT1_SUPPORT,
  1219. 1),
  1220. ATOM_DEVICE_CRT1_SUPPORT);
  1221. radeon_add_legacy_connector(dev, 1,
  1222. ATOM_DEVICE_DFP1_SUPPORT |
  1223. ATOM_DEVICE_CRT1_SUPPORT,
  1224. DRM_MODE_CONNECTOR_DVII, &ddc_i2c);
  1225. /* TV - TV DAC */
  1226. radeon_add_legacy_encoder(dev,
  1227. radeon_get_encoder_id(dev,
  1228. ATOM_DEVICE_TV1_SUPPORT,
  1229. 2),
  1230. ATOM_DEVICE_TV1_SUPPORT);
  1231. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1232. DRM_MODE_CONNECTOR_SVIDEO,
  1233. &ddc_i2c);
  1234. break;
  1235. case CT_POWERBOOK_VGA:
  1236. DRM_INFO("Connector Table: %d (powerbook vga)\n",
  1237. rdev->mode_info.connector_table);
  1238. /* LVDS */
  1239. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1240. radeon_add_legacy_encoder(dev,
  1241. radeon_get_encoder_id(dev,
  1242. ATOM_DEVICE_LCD1_SUPPORT,
  1243. 0),
  1244. ATOM_DEVICE_LCD1_SUPPORT);
  1245. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1246. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c);
  1247. /* VGA - primary dac */
  1248. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1249. radeon_add_legacy_encoder(dev,
  1250. radeon_get_encoder_id(dev,
  1251. ATOM_DEVICE_CRT1_SUPPORT,
  1252. 1),
  1253. ATOM_DEVICE_CRT1_SUPPORT);
  1254. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
  1255. DRM_MODE_CONNECTOR_VGA, &ddc_i2c);
  1256. /* TV - TV DAC */
  1257. radeon_add_legacy_encoder(dev,
  1258. radeon_get_encoder_id(dev,
  1259. ATOM_DEVICE_TV1_SUPPORT,
  1260. 2),
  1261. ATOM_DEVICE_TV1_SUPPORT);
  1262. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1263. DRM_MODE_CONNECTOR_SVIDEO,
  1264. &ddc_i2c);
  1265. break;
  1266. case CT_MINI_EXTERNAL:
  1267. DRM_INFO("Connector Table: %d (mini external tmds)\n",
  1268. rdev->mode_info.connector_table);
  1269. /* DVI-I - tv dac, ext tmds */
  1270. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_CRT2_DDC);
  1271. radeon_add_legacy_encoder(dev,
  1272. radeon_get_encoder_id(dev,
  1273. ATOM_DEVICE_DFP2_SUPPORT,
  1274. 0),
  1275. ATOM_DEVICE_DFP2_SUPPORT);
  1276. radeon_add_legacy_encoder(dev,
  1277. radeon_get_encoder_id(dev,
  1278. ATOM_DEVICE_CRT2_SUPPORT,
  1279. 2),
  1280. ATOM_DEVICE_CRT2_SUPPORT);
  1281. radeon_add_legacy_connector(dev, 0,
  1282. ATOM_DEVICE_DFP2_SUPPORT |
  1283. ATOM_DEVICE_CRT2_SUPPORT,
  1284. DRM_MODE_CONNECTOR_DVII, &ddc_i2c);
  1285. /* TV - TV DAC */
  1286. radeon_add_legacy_encoder(dev,
  1287. radeon_get_encoder_id(dev,
  1288. ATOM_DEVICE_TV1_SUPPORT,
  1289. 2),
  1290. ATOM_DEVICE_TV1_SUPPORT);
  1291. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1292. DRM_MODE_CONNECTOR_SVIDEO,
  1293. &ddc_i2c);
  1294. break;
  1295. case CT_MINI_INTERNAL:
  1296. DRM_INFO("Connector Table: %d (mini internal tmds)\n",
  1297. rdev->mode_info.connector_table);
  1298. /* DVI-I - tv dac, int 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_DFP1_SUPPORT,
  1303. 0),
  1304. ATOM_DEVICE_DFP1_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. radeon_add_legacy_connector(dev, 0,
  1311. ATOM_DEVICE_DFP1_SUPPORT |
  1312. ATOM_DEVICE_CRT2_SUPPORT,
  1313. DRM_MODE_CONNECTOR_DVII, &ddc_i2c);
  1314. /* TV - TV DAC */
  1315. radeon_add_legacy_encoder(dev,
  1316. radeon_get_encoder_id(dev,
  1317. ATOM_DEVICE_TV1_SUPPORT,
  1318. 2),
  1319. ATOM_DEVICE_TV1_SUPPORT);
  1320. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1321. DRM_MODE_CONNECTOR_SVIDEO,
  1322. &ddc_i2c);
  1323. break;
  1324. case CT_IMAC_G5_ISIGHT:
  1325. DRM_INFO("Connector Table: %d (imac g5 isight)\n",
  1326. rdev->mode_info.connector_table);
  1327. /* DVI-D - int tmds */
  1328. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_MONID);
  1329. radeon_add_legacy_encoder(dev,
  1330. radeon_get_encoder_id(dev,
  1331. ATOM_DEVICE_DFP1_SUPPORT,
  1332. 0),
  1333. ATOM_DEVICE_DFP1_SUPPORT);
  1334. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
  1335. DRM_MODE_CONNECTOR_DVID, &ddc_i2c);
  1336. /* VGA - tv dac */
  1337. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1338. radeon_add_legacy_encoder(dev,
  1339. radeon_get_encoder_id(dev,
  1340. ATOM_DEVICE_CRT2_SUPPORT,
  1341. 2),
  1342. ATOM_DEVICE_CRT2_SUPPORT);
  1343. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1344. DRM_MODE_CONNECTOR_VGA, &ddc_i2c);
  1345. /* TV - TV DAC */
  1346. radeon_add_legacy_encoder(dev,
  1347. radeon_get_encoder_id(dev,
  1348. ATOM_DEVICE_TV1_SUPPORT,
  1349. 2),
  1350. ATOM_DEVICE_TV1_SUPPORT);
  1351. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1352. DRM_MODE_CONNECTOR_SVIDEO,
  1353. &ddc_i2c);
  1354. break;
  1355. case CT_EMAC:
  1356. DRM_INFO("Connector Table: %d (emac)\n",
  1357. rdev->mode_info.connector_table);
  1358. /* VGA - primary dac */
  1359. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1360. radeon_add_legacy_encoder(dev,
  1361. radeon_get_encoder_id(dev,
  1362. ATOM_DEVICE_CRT1_SUPPORT,
  1363. 1),
  1364. ATOM_DEVICE_CRT1_SUPPORT);
  1365. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1366. DRM_MODE_CONNECTOR_VGA, &ddc_i2c);
  1367. /* VGA - tv dac */
  1368. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_CRT2_DDC);
  1369. radeon_add_legacy_encoder(dev,
  1370. radeon_get_encoder_id(dev,
  1371. ATOM_DEVICE_CRT2_SUPPORT,
  1372. 2),
  1373. ATOM_DEVICE_CRT2_SUPPORT);
  1374. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1375. DRM_MODE_CONNECTOR_VGA, &ddc_i2c);
  1376. /* TV - TV DAC */
  1377. radeon_add_legacy_encoder(dev,
  1378. radeon_get_encoder_id(dev,
  1379. ATOM_DEVICE_TV1_SUPPORT,
  1380. 2),
  1381. ATOM_DEVICE_TV1_SUPPORT);
  1382. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1383. DRM_MODE_CONNECTOR_SVIDEO,
  1384. &ddc_i2c);
  1385. break;
  1386. default:
  1387. DRM_INFO("Connector table: %d (invalid)\n",
  1388. rdev->mode_info.connector_table);
  1389. return false;
  1390. }
  1391. radeon_link_encoder_connector(dev);
  1392. return true;
  1393. }
  1394. static bool radeon_apply_legacy_quirks(struct drm_device *dev,
  1395. int bios_index,
  1396. enum radeon_combios_connector
  1397. *legacy_connector,
  1398. struct radeon_i2c_bus_rec *ddc_i2c)
  1399. {
  1400. struct radeon_device *rdev = dev->dev_private;
  1401. /* XPRESS DDC quirks */
  1402. if ((rdev->family == CHIP_RS400 ||
  1403. rdev->family == CHIP_RS480) &&
  1404. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  1405. *ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_MONID);
  1406. else if ((rdev->family == CHIP_RS400 ||
  1407. rdev->family == CHIP_RS480) &&
  1408. ddc_i2c->mask_clk_reg == RADEON_GPIO_MONID) {
  1409. ddc_i2c->valid = true;
  1410. ddc_i2c->mask_clk_mask = (0x20 << 8);
  1411. ddc_i2c->mask_data_mask = 0x80;
  1412. ddc_i2c->a_clk_mask = (0x20 << 8);
  1413. ddc_i2c->a_data_mask = 0x80;
  1414. ddc_i2c->put_clk_mask = (0x20 << 8);
  1415. ddc_i2c->put_data_mask = 0x80;
  1416. ddc_i2c->get_clk_mask = (0x20 << 8);
  1417. ddc_i2c->get_data_mask = 0x80;
  1418. ddc_i2c->mask_clk_reg = RADEON_GPIOPAD_MASK;
  1419. ddc_i2c->mask_data_reg = RADEON_GPIOPAD_MASK;
  1420. ddc_i2c->a_clk_reg = RADEON_GPIOPAD_A;
  1421. ddc_i2c->a_data_reg = RADEON_GPIOPAD_A;
  1422. ddc_i2c->put_clk_reg = RADEON_GPIOPAD_EN;
  1423. ddc_i2c->put_data_reg = RADEON_GPIOPAD_EN;
  1424. ddc_i2c->get_clk_reg = RADEON_LCD_GPIO_Y_REG;
  1425. ddc_i2c->get_data_reg = RADEON_LCD_GPIO_Y_REG;
  1426. }
  1427. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  1428. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  1429. if (dev->pdev->device == 0x515e &&
  1430. dev->pdev->subsystem_vendor == 0x1014) {
  1431. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  1432. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  1433. return false;
  1434. }
  1435. /* Some RV100 cards with 2 VGA ports show up with DVI+VGA */
  1436. if (dev->pdev->device == 0x5159 &&
  1437. dev->pdev->subsystem_vendor == 0x1002 &&
  1438. dev->pdev->subsystem_device == 0x013a) {
  1439. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  1440. *legacy_connector = CONNECTOR_CRT_LEGACY;
  1441. }
  1442. /* X300 card with extra non-existent DVI port */
  1443. if (dev->pdev->device == 0x5B60 &&
  1444. dev->pdev->subsystem_vendor == 0x17af &&
  1445. dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  1446. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  1447. return false;
  1448. }
  1449. return true;
  1450. }
  1451. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  1452. {
  1453. struct radeon_device *rdev = dev->dev_private;
  1454. uint32_t conn_info, entry, devices;
  1455. uint16_t tmp;
  1456. enum radeon_combios_ddc ddc_type;
  1457. enum radeon_combios_connector connector;
  1458. int i = 0;
  1459. struct radeon_i2c_bus_rec ddc_i2c;
  1460. if (rdev->bios == NULL)
  1461. return false;
  1462. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  1463. if (conn_info) {
  1464. for (i = 0; i < 4; i++) {
  1465. entry = conn_info + 2 + i * 2;
  1466. if (!RBIOS16(entry))
  1467. break;
  1468. tmp = RBIOS16(entry);
  1469. connector = (tmp >> 12) & 0xf;
  1470. ddc_type = (tmp >> 8) & 0xf;
  1471. switch (ddc_type) {
  1472. case DDC_MONID:
  1473. ddc_i2c =
  1474. combios_setup_i2c_bus(RADEON_GPIO_MONID);
  1475. break;
  1476. case DDC_DVI:
  1477. ddc_i2c =
  1478. combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1479. break;
  1480. case DDC_VGA:
  1481. ddc_i2c =
  1482. combios_setup_i2c_bus(RADEON_GPIO_VGA_DDC);
  1483. break;
  1484. case DDC_CRT2:
  1485. ddc_i2c =
  1486. combios_setup_i2c_bus(RADEON_GPIO_CRT2_DDC);
  1487. break;
  1488. default:
  1489. break;
  1490. }
  1491. radeon_apply_legacy_quirks(dev, i, &connector,
  1492. &ddc_i2c);
  1493. switch (connector) {
  1494. case CONNECTOR_PROPRIETARY_LEGACY:
  1495. if ((tmp >> 4) & 0x1)
  1496. devices = ATOM_DEVICE_DFP2_SUPPORT;
  1497. else
  1498. devices = ATOM_DEVICE_DFP1_SUPPORT;
  1499. radeon_add_legacy_encoder(dev,
  1500. radeon_get_encoder_id
  1501. (dev, devices, 0),
  1502. devices);
  1503. radeon_add_legacy_connector(dev, i, devices,
  1504. legacy_connector_convert
  1505. [connector],
  1506. &ddc_i2c);
  1507. break;
  1508. case CONNECTOR_CRT_LEGACY:
  1509. if (tmp & 0x1) {
  1510. devices = ATOM_DEVICE_CRT2_SUPPORT;
  1511. radeon_add_legacy_encoder(dev,
  1512. radeon_get_encoder_id
  1513. (dev,
  1514. ATOM_DEVICE_CRT2_SUPPORT,
  1515. 2),
  1516. ATOM_DEVICE_CRT2_SUPPORT);
  1517. } else {
  1518. devices = ATOM_DEVICE_CRT1_SUPPORT;
  1519. radeon_add_legacy_encoder(dev,
  1520. radeon_get_encoder_id
  1521. (dev,
  1522. ATOM_DEVICE_CRT1_SUPPORT,
  1523. 1),
  1524. ATOM_DEVICE_CRT1_SUPPORT);
  1525. }
  1526. radeon_add_legacy_connector(dev,
  1527. i,
  1528. devices,
  1529. legacy_connector_convert
  1530. [connector],
  1531. &ddc_i2c);
  1532. break;
  1533. case CONNECTOR_DVI_I_LEGACY:
  1534. devices = 0;
  1535. if (tmp & 0x1) {
  1536. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  1537. radeon_add_legacy_encoder(dev,
  1538. radeon_get_encoder_id
  1539. (dev,
  1540. ATOM_DEVICE_CRT2_SUPPORT,
  1541. 2),
  1542. ATOM_DEVICE_CRT2_SUPPORT);
  1543. } else {
  1544. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  1545. radeon_add_legacy_encoder(dev,
  1546. radeon_get_encoder_id
  1547. (dev,
  1548. ATOM_DEVICE_CRT1_SUPPORT,
  1549. 1),
  1550. ATOM_DEVICE_CRT1_SUPPORT);
  1551. }
  1552. if ((tmp >> 4) & 0x1) {
  1553. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  1554. radeon_add_legacy_encoder(dev,
  1555. radeon_get_encoder_id
  1556. (dev,
  1557. ATOM_DEVICE_DFP2_SUPPORT,
  1558. 0),
  1559. ATOM_DEVICE_DFP2_SUPPORT);
  1560. } else {
  1561. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  1562. radeon_add_legacy_encoder(dev,
  1563. radeon_get_encoder_id
  1564. (dev,
  1565. ATOM_DEVICE_DFP1_SUPPORT,
  1566. 0),
  1567. ATOM_DEVICE_DFP1_SUPPORT);
  1568. }
  1569. radeon_add_legacy_connector(dev,
  1570. i,
  1571. devices,
  1572. legacy_connector_convert
  1573. [connector],
  1574. &ddc_i2c);
  1575. break;
  1576. case CONNECTOR_DVI_D_LEGACY:
  1577. if ((tmp >> 4) & 0x1)
  1578. devices = ATOM_DEVICE_DFP2_SUPPORT;
  1579. else
  1580. devices = ATOM_DEVICE_DFP1_SUPPORT;
  1581. radeon_add_legacy_encoder(dev,
  1582. radeon_get_encoder_id
  1583. (dev, devices, 0),
  1584. devices);
  1585. radeon_add_legacy_connector(dev, i, devices,
  1586. legacy_connector_convert
  1587. [connector],
  1588. &ddc_i2c);
  1589. break;
  1590. case CONNECTOR_CTV_LEGACY:
  1591. case CONNECTOR_STV_LEGACY:
  1592. radeon_add_legacy_encoder(dev,
  1593. radeon_get_encoder_id
  1594. (dev,
  1595. ATOM_DEVICE_TV1_SUPPORT,
  1596. 2),
  1597. ATOM_DEVICE_TV1_SUPPORT);
  1598. radeon_add_legacy_connector(dev, i,
  1599. ATOM_DEVICE_TV1_SUPPORT,
  1600. legacy_connector_convert
  1601. [connector],
  1602. &ddc_i2c);
  1603. break;
  1604. default:
  1605. DRM_ERROR("Unknown connector type: %d\n",
  1606. connector);
  1607. continue;
  1608. }
  1609. }
  1610. } else {
  1611. uint16_t tmds_info =
  1612. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  1613. if (tmds_info) {
  1614. DRM_DEBUG("Found DFP table, assuming DVI connector\n");
  1615. radeon_add_legacy_encoder(dev,
  1616. radeon_get_encoder_id(dev,
  1617. ATOM_DEVICE_CRT1_SUPPORT,
  1618. 1),
  1619. ATOM_DEVICE_CRT1_SUPPORT);
  1620. radeon_add_legacy_encoder(dev,
  1621. radeon_get_encoder_id(dev,
  1622. ATOM_DEVICE_DFP1_SUPPORT,
  1623. 0),
  1624. ATOM_DEVICE_DFP1_SUPPORT);
  1625. ddc_i2c = combios_setup_i2c_bus(RADEON_GPIO_DVI_DDC);
  1626. radeon_add_legacy_connector(dev,
  1627. 0,
  1628. ATOM_DEVICE_CRT1_SUPPORT |
  1629. ATOM_DEVICE_DFP1_SUPPORT,
  1630. DRM_MODE_CONNECTOR_DVII,
  1631. &ddc_i2c);
  1632. } else {
  1633. DRM_DEBUG("No connector info found\n");
  1634. return false;
  1635. }
  1636. }
  1637. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  1638. uint16_t lcd_info =
  1639. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  1640. if (lcd_info) {
  1641. uint16_t lcd_ddc_info =
  1642. combios_get_table_offset(dev,
  1643. COMBIOS_LCD_DDC_INFO_TABLE);
  1644. radeon_add_legacy_encoder(dev,
  1645. radeon_get_encoder_id(dev,
  1646. ATOM_DEVICE_LCD1_SUPPORT,
  1647. 0),
  1648. ATOM_DEVICE_LCD1_SUPPORT);
  1649. if (lcd_ddc_info) {
  1650. ddc_type = RBIOS8(lcd_ddc_info + 2);
  1651. switch (ddc_type) {
  1652. case DDC_MONID:
  1653. ddc_i2c =
  1654. combios_setup_i2c_bus
  1655. (RADEON_GPIO_MONID);
  1656. break;
  1657. case DDC_DVI:
  1658. ddc_i2c =
  1659. combios_setup_i2c_bus
  1660. (RADEON_GPIO_DVI_DDC);
  1661. break;
  1662. case DDC_VGA:
  1663. ddc_i2c =
  1664. combios_setup_i2c_bus
  1665. (RADEON_GPIO_VGA_DDC);
  1666. break;
  1667. case DDC_CRT2:
  1668. ddc_i2c =
  1669. combios_setup_i2c_bus
  1670. (RADEON_GPIO_CRT2_DDC);
  1671. break;
  1672. case DDC_LCD:
  1673. ddc_i2c =
  1674. combios_setup_i2c_bus
  1675. (RADEON_LCD_GPIO_MASK);
  1676. ddc_i2c.mask_clk_mask =
  1677. RBIOS32(lcd_ddc_info + 3);
  1678. ddc_i2c.mask_data_mask =
  1679. RBIOS32(lcd_ddc_info + 7);
  1680. ddc_i2c.a_clk_mask =
  1681. RBIOS32(lcd_ddc_info + 3);
  1682. ddc_i2c.a_data_mask =
  1683. RBIOS32(lcd_ddc_info + 7);
  1684. ddc_i2c.put_clk_mask =
  1685. RBIOS32(lcd_ddc_info + 3);
  1686. ddc_i2c.put_data_mask =
  1687. RBIOS32(lcd_ddc_info + 7);
  1688. ddc_i2c.get_clk_mask =
  1689. RBIOS32(lcd_ddc_info + 3);
  1690. ddc_i2c.get_data_mask =
  1691. RBIOS32(lcd_ddc_info + 7);
  1692. break;
  1693. case DDC_GPIO:
  1694. ddc_i2c =
  1695. combios_setup_i2c_bus
  1696. (RADEON_MDGPIO_EN_REG);
  1697. ddc_i2c.mask_clk_mask =
  1698. RBIOS32(lcd_ddc_info + 3);
  1699. ddc_i2c.mask_data_mask =
  1700. RBIOS32(lcd_ddc_info + 7);
  1701. ddc_i2c.a_clk_mask =
  1702. RBIOS32(lcd_ddc_info + 3);
  1703. ddc_i2c.a_data_mask =
  1704. RBIOS32(lcd_ddc_info + 7);
  1705. ddc_i2c.put_clk_mask =
  1706. RBIOS32(lcd_ddc_info + 3);
  1707. ddc_i2c.put_data_mask =
  1708. RBIOS32(lcd_ddc_info + 7);
  1709. ddc_i2c.get_clk_mask =
  1710. RBIOS32(lcd_ddc_info + 3);
  1711. ddc_i2c.get_data_mask =
  1712. RBIOS32(lcd_ddc_info + 7);
  1713. break;
  1714. default:
  1715. ddc_i2c.valid = false;
  1716. break;
  1717. }
  1718. DRM_DEBUG("LCD DDC Info Table found!\n");
  1719. } else
  1720. ddc_i2c.valid = false;
  1721. radeon_add_legacy_connector(dev,
  1722. 5,
  1723. ATOM_DEVICE_LCD1_SUPPORT,
  1724. DRM_MODE_CONNECTOR_LVDS,
  1725. &ddc_i2c);
  1726. }
  1727. }
  1728. /* check TV table */
  1729. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1730. uint32_t tv_info =
  1731. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  1732. if (tv_info) {
  1733. if (RBIOS8(tv_info + 6) == 'T') {
  1734. radeon_add_legacy_encoder(dev,
  1735. radeon_get_encoder_id
  1736. (dev,
  1737. ATOM_DEVICE_TV1_SUPPORT,
  1738. 2),
  1739. ATOM_DEVICE_TV1_SUPPORT);
  1740. radeon_add_legacy_connector(dev, 6,
  1741. ATOM_DEVICE_TV1_SUPPORT,
  1742. DRM_MODE_CONNECTOR_SVIDEO,
  1743. &ddc_i2c);
  1744. }
  1745. }
  1746. }
  1747. radeon_link_encoder_connector(dev);
  1748. return true;
  1749. }
  1750. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  1751. {
  1752. struct radeon_device *rdev = dev->dev_private;
  1753. if (offset) {
  1754. while (RBIOS16(offset)) {
  1755. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  1756. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  1757. uint32_t val, and_mask, or_mask;
  1758. uint32_t tmp;
  1759. offset += 2;
  1760. switch (cmd) {
  1761. case 0:
  1762. val = RBIOS32(offset);
  1763. offset += 4;
  1764. WREG32(addr, val);
  1765. break;
  1766. case 1:
  1767. val = RBIOS32(offset);
  1768. offset += 4;
  1769. WREG32(addr, val);
  1770. break;
  1771. case 2:
  1772. and_mask = RBIOS32(offset);
  1773. offset += 4;
  1774. or_mask = RBIOS32(offset);
  1775. offset += 4;
  1776. tmp = RREG32(addr);
  1777. tmp &= and_mask;
  1778. tmp |= or_mask;
  1779. WREG32(addr, tmp);
  1780. break;
  1781. case 3:
  1782. and_mask = RBIOS32(offset);
  1783. offset += 4;
  1784. or_mask = RBIOS32(offset);
  1785. offset += 4;
  1786. tmp = RREG32(addr);
  1787. tmp &= and_mask;
  1788. tmp |= or_mask;
  1789. WREG32(addr, tmp);
  1790. break;
  1791. case 4:
  1792. val = RBIOS16(offset);
  1793. offset += 2;
  1794. udelay(val);
  1795. break;
  1796. case 5:
  1797. val = RBIOS16(offset);
  1798. offset += 2;
  1799. switch (addr) {
  1800. case 8:
  1801. while (val--) {
  1802. if (!
  1803. (RREG32_PLL
  1804. (RADEON_CLK_PWRMGT_CNTL) &
  1805. RADEON_MC_BUSY))
  1806. break;
  1807. }
  1808. break;
  1809. case 9:
  1810. while (val--) {
  1811. if ((RREG32(RADEON_MC_STATUS) &
  1812. RADEON_MC_IDLE))
  1813. break;
  1814. }
  1815. break;
  1816. default:
  1817. break;
  1818. }
  1819. break;
  1820. default:
  1821. break;
  1822. }
  1823. }
  1824. }
  1825. }
  1826. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  1827. {
  1828. struct radeon_device *rdev = dev->dev_private;
  1829. if (offset) {
  1830. while (RBIOS8(offset)) {
  1831. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  1832. uint8_t addr = (RBIOS8(offset) & 0x3f);
  1833. uint32_t val, shift, tmp;
  1834. uint32_t and_mask, or_mask;
  1835. offset++;
  1836. switch (cmd) {
  1837. case 0:
  1838. val = RBIOS32(offset);
  1839. offset += 4;
  1840. WREG32_PLL(addr, val);
  1841. break;
  1842. case 1:
  1843. shift = RBIOS8(offset) * 8;
  1844. offset++;
  1845. and_mask = RBIOS8(offset) << shift;
  1846. and_mask |= ~(0xff << shift);
  1847. offset++;
  1848. or_mask = RBIOS8(offset) << shift;
  1849. offset++;
  1850. tmp = RREG32_PLL(addr);
  1851. tmp &= and_mask;
  1852. tmp |= or_mask;
  1853. WREG32_PLL(addr, tmp);
  1854. break;
  1855. case 2:
  1856. case 3:
  1857. tmp = 1000;
  1858. switch (addr) {
  1859. case 1:
  1860. udelay(150);
  1861. break;
  1862. case 2:
  1863. udelay(1000);
  1864. break;
  1865. case 3:
  1866. while (tmp--) {
  1867. if (!
  1868. (RREG32_PLL
  1869. (RADEON_CLK_PWRMGT_CNTL) &
  1870. RADEON_MC_BUSY))
  1871. break;
  1872. }
  1873. break;
  1874. case 4:
  1875. while (tmp--) {
  1876. if (RREG32_PLL
  1877. (RADEON_CLK_PWRMGT_CNTL) &
  1878. RADEON_DLL_READY)
  1879. break;
  1880. }
  1881. break;
  1882. case 5:
  1883. tmp =
  1884. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  1885. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  1886. #if 0
  1887. uint32_t mclk_cntl =
  1888. RREG32_PLL
  1889. (RADEON_MCLK_CNTL);
  1890. mclk_cntl &= 0xffff0000;
  1891. /*mclk_cntl |= 0x00001111;*//* ??? */
  1892. WREG32_PLL(RADEON_MCLK_CNTL,
  1893. mclk_cntl);
  1894. udelay(10000);
  1895. #endif
  1896. WREG32_PLL
  1897. (RADEON_CLK_PWRMGT_CNTL,
  1898. tmp &
  1899. ~RADEON_CG_NO1_DEBUG_0);
  1900. udelay(10000);
  1901. }
  1902. break;
  1903. default:
  1904. break;
  1905. }
  1906. break;
  1907. default:
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. static void combios_parse_ram_reset_table(struct drm_device *dev,
  1914. uint16_t offset)
  1915. {
  1916. struct radeon_device *rdev = dev->dev_private;
  1917. uint32_t tmp;
  1918. if (offset) {
  1919. uint8_t val = RBIOS8(offset);
  1920. while (val != 0xff) {
  1921. offset++;
  1922. if (val == 0x0f) {
  1923. uint32_t channel_complete_mask;
  1924. if (ASIC_IS_R300(rdev))
  1925. channel_complete_mask =
  1926. R300_MEM_PWRUP_COMPLETE;
  1927. else
  1928. channel_complete_mask =
  1929. RADEON_MEM_PWRUP_COMPLETE;
  1930. tmp = 20000;
  1931. while (tmp--) {
  1932. if ((RREG32(RADEON_MEM_STR_CNTL) &
  1933. channel_complete_mask) ==
  1934. channel_complete_mask)
  1935. break;
  1936. }
  1937. } else {
  1938. uint32_t or_mask = RBIOS16(offset);
  1939. offset += 2;
  1940. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  1941. tmp &= RADEON_SDRAM_MODE_MASK;
  1942. tmp |= or_mask;
  1943. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  1944. or_mask = val << 24;
  1945. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  1946. tmp &= RADEON_B3MEM_RESET_MASK;
  1947. tmp |= or_mask;
  1948. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  1949. }
  1950. val = RBIOS8(offset);
  1951. }
  1952. }
  1953. }
  1954. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  1955. int mem_addr_mapping)
  1956. {
  1957. struct radeon_device *rdev = dev->dev_private;
  1958. uint32_t mem_cntl;
  1959. uint32_t mem_size;
  1960. uint32_t addr = 0;
  1961. mem_cntl = RREG32(RADEON_MEM_CNTL);
  1962. if (mem_cntl & RV100_HALF_MODE)
  1963. ram /= 2;
  1964. mem_size = ram;
  1965. mem_cntl &= ~(0xff << 8);
  1966. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  1967. WREG32(RADEON_MEM_CNTL, mem_cntl);
  1968. RREG32(RADEON_MEM_CNTL);
  1969. /* sdram reset ? */
  1970. /* something like this???? */
  1971. while (ram--) {
  1972. addr = ram * 1024 * 1024;
  1973. /* write to each page */
  1974. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  1975. WREG32(RADEON_MM_DATA, 0xdeadbeef);
  1976. /* read back and verify */
  1977. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  1978. if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
  1979. return 0;
  1980. }
  1981. return mem_size;
  1982. }
  1983. static void combios_write_ram_size(struct drm_device *dev)
  1984. {
  1985. struct radeon_device *rdev = dev->dev_private;
  1986. uint8_t rev;
  1987. uint16_t offset;
  1988. uint32_t mem_size = 0;
  1989. uint32_t mem_cntl = 0;
  1990. /* should do something smarter here I guess... */
  1991. if (rdev->flags & RADEON_IS_IGP)
  1992. return;
  1993. /* first check detected mem table */
  1994. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  1995. if (offset) {
  1996. rev = RBIOS8(offset);
  1997. if (rev < 3) {
  1998. mem_cntl = RBIOS32(offset + 1);
  1999. mem_size = RBIOS16(offset + 5);
  2000. if (((rdev->flags & RADEON_FAMILY_MASK) < CHIP_R200) &&
  2001. ((dev->pdev->device != 0x515e)
  2002. && (dev->pdev->device != 0x5969)))
  2003. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2004. }
  2005. }
  2006. if (!mem_size) {
  2007. offset =
  2008. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  2009. if (offset) {
  2010. rev = RBIOS8(offset - 1);
  2011. if (rev < 1) {
  2012. if (((rdev->flags & RADEON_FAMILY_MASK) <
  2013. CHIP_R200)
  2014. && ((dev->pdev->device != 0x515e)
  2015. && (dev->pdev->device != 0x5969))) {
  2016. int ram = 0;
  2017. int mem_addr_mapping = 0;
  2018. while (RBIOS8(offset)) {
  2019. ram = RBIOS8(offset);
  2020. mem_addr_mapping =
  2021. RBIOS8(offset + 1);
  2022. if (mem_addr_mapping != 0x25)
  2023. ram *= 2;
  2024. mem_size =
  2025. combios_detect_ram(dev, ram,
  2026. mem_addr_mapping);
  2027. if (mem_size)
  2028. break;
  2029. offset += 2;
  2030. }
  2031. } else
  2032. mem_size = RBIOS8(offset);
  2033. } else {
  2034. mem_size = RBIOS8(offset);
  2035. mem_size *= 2; /* convert to MB */
  2036. }
  2037. }
  2038. }
  2039. mem_size *= (1024 * 1024); /* convert to bytes */
  2040. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  2041. }
  2042. void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
  2043. {
  2044. uint16_t dyn_clk_info =
  2045. combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  2046. if (dyn_clk_info)
  2047. combios_parse_pll_table(dev, dyn_clk_info);
  2048. }
  2049. void radeon_combios_asic_init(struct drm_device *dev)
  2050. {
  2051. struct radeon_device *rdev = dev->dev_private;
  2052. uint16_t table;
  2053. /* port hardcoded mac stuff from radeonfb */
  2054. if (rdev->bios == NULL)
  2055. return;
  2056. /* ASIC INIT 1 */
  2057. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  2058. if (table)
  2059. combios_parse_mmio_table(dev, table);
  2060. /* PLL INIT */
  2061. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  2062. if (table)
  2063. combios_parse_pll_table(dev, table);
  2064. /* ASIC INIT 2 */
  2065. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  2066. if (table)
  2067. combios_parse_mmio_table(dev, table);
  2068. if (!(rdev->flags & RADEON_IS_IGP)) {
  2069. /* ASIC INIT 4 */
  2070. table =
  2071. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  2072. if (table)
  2073. combios_parse_mmio_table(dev, table);
  2074. /* RAM RESET */
  2075. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  2076. if (table)
  2077. combios_parse_ram_reset_table(dev, table);
  2078. /* ASIC INIT 3 */
  2079. table =
  2080. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  2081. if (table)
  2082. combios_parse_mmio_table(dev, table);
  2083. /* write CONFIG_MEMSIZE */
  2084. combios_write_ram_size(dev);
  2085. }
  2086. /* DYN CLK 1 */
  2087. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  2088. if (table)
  2089. combios_parse_pll_table(dev, table);
  2090. }
  2091. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  2092. {
  2093. struct radeon_device *rdev = dev->dev_private;
  2094. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  2095. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2096. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2097. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  2098. /* let the bios control the backlight */
  2099. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  2100. /* tell the bios not to handle mode switching */
  2101. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  2102. RADEON_ACC_MODE_CHANGE);
  2103. /* tell the bios a driver is loaded */
  2104. bios_7_scratch |= RADEON_DRV_LOADED;
  2105. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2106. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2107. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  2108. }
  2109. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  2110. {
  2111. struct drm_device *dev = encoder->dev;
  2112. struct radeon_device *rdev = dev->dev_private;
  2113. uint32_t bios_6_scratch;
  2114. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2115. if (lock)
  2116. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  2117. else
  2118. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  2119. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2120. }
  2121. void
  2122. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  2123. struct drm_encoder *encoder,
  2124. bool connected)
  2125. {
  2126. struct drm_device *dev = connector->dev;
  2127. struct radeon_device *rdev = dev->dev_private;
  2128. struct radeon_connector *radeon_connector =
  2129. to_radeon_connector(connector);
  2130. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2131. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  2132. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  2133. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2134. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2135. if (connected) {
  2136. DRM_DEBUG("TV1 connected\n");
  2137. /* fix me */
  2138. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  2139. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  2140. bios_5_scratch |= RADEON_TV1_ON;
  2141. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  2142. } else {
  2143. DRM_DEBUG("TV1 disconnected\n");
  2144. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  2145. bios_5_scratch &= ~RADEON_TV1_ON;
  2146. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  2147. }
  2148. }
  2149. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2150. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2151. if (connected) {
  2152. DRM_DEBUG("LCD1 connected\n");
  2153. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  2154. bios_5_scratch |= RADEON_LCD1_ON;
  2155. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  2156. } else {
  2157. DRM_DEBUG("LCD1 disconnected\n");
  2158. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  2159. bios_5_scratch &= ~RADEON_LCD1_ON;
  2160. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  2161. }
  2162. }
  2163. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2164. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2165. if (connected) {
  2166. DRM_DEBUG("CRT1 connected\n");
  2167. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  2168. bios_5_scratch |= RADEON_CRT1_ON;
  2169. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  2170. } else {
  2171. DRM_DEBUG("CRT1 disconnected\n");
  2172. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  2173. bios_5_scratch &= ~RADEON_CRT1_ON;
  2174. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  2175. }
  2176. }
  2177. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2178. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2179. if (connected) {
  2180. DRM_DEBUG("CRT2 connected\n");
  2181. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  2182. bios_5_scratch |= RADEON_CRT2_ON;
  2183. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  2184. } else {
  2185. DRM_DEBUG("CRT2 disconnected\n");
  2186. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  2187. bios_5_scratch &= ~RADEON_CRT2_ON;
  2188. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  2189. }
  2190. }
  2191. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2192. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2193. if (connected) {
  2194. DRM_DEBUG("DFP1 connected\n");
  2195. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  2196. bios_5_scratch |= RADEON_DFP1_ON;
  2197. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  2198. } else {
  2199. DRM_DEBUG("DFP1 disconnected\n");
  2200. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  2201. bios_5_scratch &= ~RADEON_DFP1_ON;
  2202. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  2203. }
  2204. }
  2205. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2206. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2207. if (connected) {
  2208. DRM_DEBUG("DFP2 connected\n");
  2209. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  2210. bios_5_scratch |= RADEON_DFP2_ON;
  2211. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  2212. } else {
  2213. DRM_DEBUG("DFP2 disconnected\n");
  2214. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  2215. bios_5_scratch &= ~RADEON_DFP2_ON;
  2216. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  2217. }
  2218. }
  2219. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  2220. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  2221. }
  2222. void
  2223. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2224. {
  2225. struct drm_device *dev = encoder->dev;
  2226. struct radeon_device *rdev = dev->dev_private;
  2227. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2228. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  2229. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2230. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  2231. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  2232. }
  2233. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2234. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  2235. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  2236. }
  2237. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2238. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  2239. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  2240. }
  2241. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2242. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  2243. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  2244. }
  2245. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2246. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  2247. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  2248. }
  2249. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2250. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  2251. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  2252. }
  2253. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  2254. }
  2255. void
  2256. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2257. {
  2258. struct drm_device *dev = encoder->dev;
  2259. struct radeon_device *rdev = dev->dev_private;
  2260. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2261. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2262. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  2263. if (on)
  2264. bios_6_scratch |= RADEON_TV_DPMS_ON;
  2265. else
  2266. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  2267. }
  2268. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  2269. if (on)
  2270. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  2271. else
  2272. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  2273. }
  2274. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  2275. if (on)
  2276. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  2277. else
  2278. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  2279. }
  2280. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  2281. if (on)
  2282. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  2283. else
  2284. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  2285. }
  2286. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2287. }