radeon_combios.c 85 KB

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