radeon_combios.c 81 KB

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