radeon_combios.c 70 KB

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