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