radeon_combios.c 85 KB

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