radeon_combios.c 102 KB

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