radeon_combios.c 99 KB

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