radeon_combios.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627
  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 <linux/pci.h>
  28. #include <drm/drm_device.h>
  29. #include <drm/radeon_drm.h>
  30. #include "radeon.h"
  31. #include "radeon_legacy_encoders.h"
  32. #include "atom.h"
  33. #ifdef CONFIG_PPC_PMAC
  34. /* not sure which of these are needed */
  35. #include <asm/machdep.h>
  36. #include <asm/pmac_feature.h>
  37. #include <asm/prom.h>
  38. #endif /* CONFIG_PPC_PMAC */
  39. /* old legacy ATI BIOS routines */
  40. /* COMBIOS table offsets */
  41. enum radeon_combios_table_offset {
  42. /* absolute offset tables */
  43. COMBIOS_ASIC_INIT_1_TABLE,
  44. COMBIOS_BIOS_SUPPORT_TABLE,
  45. COMBIOS_DAC_PROGRAMMING_TABLE,
  46. COMBIOS_MAX_COLOR_DEPTH_TABLE,
  47. COMBIOS_CRTC_INFO_TABLE,
  48. COMBIOS_PLL_INFO_TABLE,
  49. COMBIOS_TV_INFO_TABLE,
  50. COMBIOS_DFP_INFO_TABLE,
  51. COMBIOS_HW_CONFIG_INFO_TABLE,
  52. COMBIOS_MULTIMEDIA_INFO_TABLE,
  53. COMBIOS_TV_STD_PATCH_TABLE,
  54. COMBIOS_LCD_INFO_TABLE,
  55. COMBIOS_MOBILE_INFO_TABLE,
  56. COMBIOS_PLL_INIT_TABLE,
  57. COMBIOS_MEM_CONFIG_TABLE,
  58. COMBIOS_SAVE_MASK_TABLE,
  59. COMBIOS_HARDCODED_EDID_TABLE,
  60. COMBIOS_ASIC_INIT_2_TABLE,
  61. COMBIOS_CONNECTOR_INFO_TABLE,
  62. COMBIOS_DYN_CLK_1_TABLE,
  63. COMBIOS_RESERVED_MEM_TABLE,
  64. COMBIOS_EXT_TMDS_INFO_TABLE,
  65. COMBIOS_MEM_CLK_INFO_TABLE,
  66. COMBIOS_EXT_DAC_INFO_TABLE,
  67. COMBIOS_MISC_INFO_TABLE,
  68. COMBIOS_CRT_INFO_TABLE,
  69. COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE,
  70. COMBIOS_COMPONENT_VIDEO_INFO_TABLE,
  71. COMBIOS_FAN_SPEED_INFO_TABLE,
  72. COMBIOS_OVERDRIVE_INFO_TABLE,
  73. COMBIOS_OEM_INFO_TABLE,
  74. COMBIOS_DYN_CLK_2_TABLE,
  75. COMBIOS_POWER_CONNECTOR_INFO_TABLE,
  76. COMBIOS_I2C_INFO_TABLE,
  77. /* relative offset tables */
  78. COMBIOS_ASIC_INIT_3_TABLE, /* offset from misc info */
  79. COMBIOS_ASIC_INIT_4_TABLE, /* offset from misc info */
  80. COMBIOS_DETECTED_MEM_TABLE, /* offset from misc info */
  81. COMBIOS_ASIC_INIT_5_TABLE, /* offset from misc info */
  82. COMBIOS_RAM_RESET_TABLE, /* offset from mem config */
  83. COMBIOS_POWERPLAY_INFO_TABLE, /* offset from mobile info */
  84. COMBIOS_GPIO_INFO_TABLE, /* offset from mobile info */
  85. COMBIOS_LCD_DDC_INFO_TABLE, /* offset from mobile info */
  86. COMBIOS_TMDS_POWER_TABLE, /* offset from mobile info */
  87. COMBIOS_TMDS_POWER_ON_TABLE, /* offset from tmds power */
  88. COMBIOS_TMDS_POWER_OFF_TABLE, /* offset from tmds power */
  89. };
  90. enum radeon_combios_ddc {
  91. DDC_NONE_DETECTED,
  92. DDC_MONID,
  93. DDC_DVI,
  94. DDC_VGA,
  95. DDC_CRT2,
  96. DDC_LCD,
  97. DDC_GPIO,
  98. };
  99. enum radeon_combios_connector {
  100. CONNECTOR_NONE_LEGACY,
  101. CONNECTOR_PROPRIETARY_LEGACY,
  102. CONNECTOR_CRT_LEGACY,
  103. CONNECTOR_DVI_I_LEGACY,
  104. CONNECTOR_DVI_D_LEGACY,
  105. CONNECTOR_CTV_LEGACY,
  106. CONNECTOR_STV_LEGACY,
  107. CONNECTOR_UNSUPPORTED_LEGACY
  108. };
  109. static const int legacy_connector_convert[] = {
  110. DRM_MODE_CONNECTOR_Unknown,
  111. DRM_MODE_CONNECTOR_DVID,
  112. DRM_MODE_CONNECTOR_VGA,
  113. DRM_MODE_CONNECTOR_DVII,
  114. DRM_MODE_CONNECTOR_DVID,
  115. DRM_MODE_CONNECTOR_Composite,
  116. DRM_MODE_CONNECTOR_SVIDEO,
  117. DRM_MODE_CONNECTOR_Unknown,
  118. };
  119. static uint16_t combios_get_table_offset(struct drm_device *dev,
  120. enum radeon_combios_table_offset table)
  121. {
  122. struct radeon_device *rdev = dev->dev_private;
  123. int rev, size;
  124. uint16_t offset = 0, check_offset;
  125. if (!rdev->bios)
  126. return 0;
  127. switch (table) {
  128. /* absolute offset tables */
  129. case COMBIOS_ASIC_INIT_1_TABLE:
  130. check_offset = 0xc;
  131. break;
  132. case COMBIOS_BIOS_SUPPORT_TABLE:
  133. check_offset = 0x14;
  134. break;
  135. case COMBIOS_DAC_PROGRAMMING_TABLE:
  136. check_offset = 0x2a;
  137. break;
  138. case COMBIOS_MAX_COLOR_DEPTH_TABLE:
  139. check_offset = 0x2c;
  140. break;
  141. case COMBIOS_CRTC_INFO_TABLE:
  142. check_offset = 0x2e;
  143. break;
  144. case COMBIOS_PLL_INFO_TABLE:
  145. check_offset = 0x30;
  146. break;
  147. case COMBIOS_TV_INFO_TABLE:
  148. check_offset = 0x32;
  149. break;
  150. case COMBIOS_DFP_INFO_TABLE:
  151. check_offset = 0x34;
  152. break;
  153. case COMBIOS_HW_CONFIG_INFO_TABLE:
  154. check_offset = 0x36;
  155. break;
  156. case COMBIOS_MULTIMEDIA_INFO_TABLE:
  157. check_offset = 0x38;
  158. break;
  159. case COMBIOS_TV_STD_PATCH_TABLE:
  160. check_offset = 0x3e;
  161. break;
  162. case COMBIOS_LCD_INFO_TABLE:
  163. check_offset = 0x40;
  164. break;
  165. case COMBIOS_MOBILE_INFO_TABLE:
  166. check_offset = 0x42;
  167. break;
  168. case COMBIOS_PLL_INIT_TABLE:
  169. check_offset = 0x46;
  170. break;
  171. case COMBIOS_MEM_CONFIG_TABLE:
  172. check_offset = 0x48;
  173. break;
  174. case COMBIOS_SAVE_MASK_TABLE:
  175. check_offset = 0x4a;
  176. break;
  177. case COMBIOS_HARDCODED_EDID_TABLE:
  178. check_offset = 0x4c;
  179. break;
  180. case COMBIOS_ASIC_INIT_2_TABLE:
  181. check_offset = 0x4e;
  182. break;
  183. case COMBIOS_CONNECTOR_INFO_TABLE:
  184. check_offset = 0x50;
  185. break;
  186. case COMBIOS_DYN_CLK_1_TABLE:
  187. check_offset = 0x52;
  188. break;
  189. case COMBIOS_RESERVED_MEM_TABLE:
  190. check_offset = 0x54;
  191. break;
  192. case COMBIOS_EXT_TMDS_INFO_TABLE:
  193. check_offset = 0x58;
  194. break;
  195. case COMBIOS_MEM_CLK_INFO_TABLE:
  196. check_offset = 0x5a;
  197. break;
  198. case COMBIOS_EXT_DAC_INFO_TABLE:
  199. check_offset = 0x5c;
  200. break;
  201. case COMBIOS_MISC_INFO_TABLE:
  202. check_offset = 0x5e;
  203. break;
  204. case COMBIOS_CRT_INFO_TABLE:
  205. check_offset = 0x60;
  206. break;
  207. case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
  208. check_offset = 0x62;
  209. break;
  210. case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
  211. check_offset = 0x64;
  212. break;
  213. case COMBIOS_FAN_SPEED_INFO_TABLE:
  214. check_offset = 0x66;
  215. break;
  216. case COMBIOS_OVERDRIVE_INFO_TABLE:
  217. check_offset = 0x68;
  218. break;
  219. case COMBIOS_OEM_INFO_TABLE:
  220. check_offset = 0x6a;
  221. break;
  222. case COMBIOS_DYN_CLK_2_TABLE:
  223. check_offset = 0x6c;
  224. break;
  225. case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
  226. check_offset = 0x6e;
  227. break;
  228. case COMBIOS_I2C_INFO_TABLE:
  229. check_offset = 0x70;
  230. break;
  231. /* relative offset tables */
  232. case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */
  233. check_offset =
  234. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  235. if (check_offset) {
  236. rev = RBIOS8(check_offset);
  237. if (rev > 0) {
  238. check_offset = RBIOS16(check_offset + 0x3);
  239. if (check_offset)
  240. offset = check_offset;
  241. }
  242. }
  243. break;
  244. case COMBIOS_ASIC_INIT_4_TABLE: /* offset from misc info */
  245. check_offset =
  246. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  247. if (check_offset) {
  248. rev = RBIOS8(check_offset);
  249. if (rev > 0) {
  250. check_offset = RBIOS16(check_offset + 0x5);
  251. if (check_offset)
  252. offset = check_offset;
  253. }
  254. }
  255. break;
  256. case COMBIOS_DETECTED_MEM_TABLE: /* offset from misc info */
  257. check_offset =
  258. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  259. if (check_offset) {
  260. rev = RBIOS8(check_offset);
  261. if (rev > 0) {
  262. check_offset = RBIOS16(check_offset + 0x7);
  263. if (check_offset)
  264. offset = check_offset;
  265. }
  266. }
  267. break;
  268. case COMBIOS_ASIC_INIT_5_TABLE: /* offset from misc info */
  269. check_offset =
  270. combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
  271. if (check_offset) {
  272. rev = RBIOS8(check_offset);
  273. if (rev == 2) {
  274. check_offset = RBIOS16(check_offset + 0x9);
  275. if (check_offset)
  276. offset = check_offset;
  277. }
  278. }
  279. break;
  280. case COMBIOS_RAM_RESET_TABLE: /* offset from mem config */
  281. check_offset =
  282. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  283. if (check_offset) {
  284. while (RBIOS8(check_offset++));
  285. check_offset += 2;
  286. if (check_offset)
  287. offset = check_offset;
  288. }
  289. break;
  290. case COMBIOS_POWERPLAY_INFO_TABLE: /* offset from mobile info */
  291. check_offset =
  292. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  293. if (check_offset) {
  294. check_offset = RBIOS16(check_offset + 0x11);
  295. if (check_offset)
  296. offset = check_offset;
  297. }
  298. break;
  299. case COMBIOS_GPIO_INFO_TABLE: /* offset from mobile info */
  300. check_offset =
  301. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  302. if (check_offset) {
  303. check_offset = RBIOS16(check_offset + 0x13);
  304. if (check_offset)
  305. offset = check_offset;
  306. }
  307. break;
  308. case COMBIOS_LCD_DDC_INFO_TABLE: /* offset from mobile info */
  309. check_offset =
  310. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  311. if (check_offset) {
  312. check_offset = RBIOS16(check_offset + 0x15);
  313. if (check_offset)
  314. offset = check_offset;
  315. }
  316. break;
  317. case COMBIOS_TMDS_POWER_TABLE: /* offset from mobile info */
  318. check_offset =
  319. combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
  320. if (check_offset) {
  321. check_offset = RBIOS16(check_offset + 0x17);
  322. if (check_offset)
  323. offset = check_offset;
  324. }
  325. break;
  326. case COMBIOS_TMDS_POWER_ON_TABLE: /* offset from tmds power */
  327. check_offset =
  328. combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
  329. if (check_offset) {
  330. check_offset = RBIOS16(check_offset + 0x2);
  331. if (check_offset)
  332. offset = check_offset;
  333. }
  334. break;
  335. case COMBIOS_TMDS_POWER_OFF_TABLE: /* offset from tmds power */
  336. check_offset =
  337. combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
  338. if (check_offset) {
  339. check_offset = RBIOS16(check_offset + 0x4);
  340. if (check_offset)
  341. offset = check_offset;
  342. }
  343. break;
  344. default:
  345. check_offset = 0;
  346. break;
  347. }
  348. size = RBIOS8(rdev->bios_header_start + 0x6);
  349. /* check absolute offset tables */
  350. if (table < COMBIOS_ASIC_INIT_3_TABLE && check_offset && check_offset < size)
  351. offset = RBIOS16(rdev->bios_header_start + check_offset);
  352. return offset;
  353. }
  354. bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
  355. {
  356. int edid_info, size;
  357. struct edid *edid;
  358. unsigned char *raw;
  359. edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
  360. if (!edid_info)
  361. return false;
  362. raw = rdev->bios + edid_info;
  363. size = EDID_LENGTH * (raw[0x7e] + 1);
  364. edid = kmalloc(size, GFP_KERNEL);
  365. if (edid == NULL)
  366. return false;
  367. memcpy((unsigned char *)edid, raw, size);
  368. if (!drm_edid_is_valid(edid)) {
  369. kfree(edid);
  370. return false;
  371. }
  372. rdev->mode_info.bios_hardcoded_edid = edid;
  373. rdev->mode_info.bios_hardcoded_edid_size = size;
  374. return true;
  375. }
  376. /* this is used for atom LCDs as well */
  377. struct edid *
  378. radeon_bios_get_hardcoded_edid(struct radeon_device *rdev)
  379. {
  380. struct edid *edid;
  381. if (rdev->mode_info.bios_hardcoded_edid) {
  382. edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
  383. if (edid) {
  384. memcpy((unsigned char *)edid,
  385. (unsigned char *)rdev->mode_info.bios_hardcoded_edid,
  386. rdev->mode_info.bios_hardcoded_edid_size);
  387. return edid;
  388. }
  389. }
  390. return NULL;
  391. }
  392. static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
  393. enum radeon_combios_ddc ddc,
  394. u32 clk_mask,
  395. u32 data_mask)
  396. {
  397. struct radeon_i2c_bus_rec i2c;
  398. int ddc_line = 0;
  399. /* ddc id = mask reg
  400. * DDC_NONE_DETECTED = none
  401. * DDC_DVI = RADEON_GPIO_DVI_DDC
  402. * DDC_VGA = RADEON_GPIO_VGA_DDC
  403. * DDC_LCD = RADEON_GPIOPAD_MASK
  404. * DDC_GPIO = RADEON_MDGPIO_MASK
  405. * r1xx
  406. * DDC_MONID = RADEON_GPIO_MONID
  407. * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
  408. * r200
  409. * DDC_MONID = RADEON_GPIO_MONID
  410. * DDC_CRT2 = RADEON_GPIO_DVI_DDC
  411. * r300/r350
  412. * DDC_MONID = RADEON_GPIO_DVI_DDC
  413. * DDC_CRT2 = RADEON_GPIO_DVI_DDC
  414. * rv2xx/rv3xx
  415. * DDC_MONID = RADEON_GPIO_MONID
  416. * DDC_CRT2 = RADEON_GPIO_MONID
  417. * rs3xx/rs4xx
  418. * DDC_MONID = RADEON_GPIOPAD_MASK
  419. * DDC_CRT2 = RADEON_GPIO_MONID
  420. */
  421. switch (ddc) {
  422. case DDC_NONE_DETECTED:
  423. default:
  424. ddc_line = 0;
  425. break;
  426. case DDC_DVI:
  427. ddc_line = RADEON_GPIO_DVI_DDC;
  428. break;
  429. case DDC_VGA:
  430. ddc_line = RADEON_GPIO_VGA_DDC;
  431. break;
  432. case DDC_LCD:
  433. ddc_line = RADEON_GPIOPAD_MASK;
  434. break;
  435. case DDC_GPIO:
  436. ddc_line = RADEON_MDGPIO_MASK;
  437. break;
  438. case DDC_MONID:
  439. if (rdev->family == CHIP_RS300 ||
  440. rdev->family == CHIP_RS400 ||
  441. rdev->family == CHIP_RS480)
  442. ddc_line = RADEON_GPIOPAD_MASK;
  443. else if (rdev->family == CHIP_R300 ||
  444. rdev->family == CHIP_R350) {
  445. ddc_line = RADEON_GPIO_DVI_DDC;
  446. ddc = DDC_DVI;
  447. } else
  448. ddc_line = RADEON_GPIO_MONID;
  449. break;
  450. case DDC_CRT2:
  451. if (rdev->family == CHIP_R200 ||
  452. rdev->family == CHIP_R300 ||
  453. rdev->family == CHIP_R350) {
  454. ddc_line = RADEON_GPIO_DVI_DDC;
  455. ddc = DDC_DVI;
  456. } else if (rdev->family == CHIP_RS300 ||
  457. rdev->family == CHIP_RS400 ||
  458. rdev->family == CHIP_RS480)
  459. ddc_line = RADEON_GPIO_MONID;
  460. else if (rdev->family >= CHIP_RV350) {
  461. ddc_line = RADEON_GPIO_MONID;
  462. ddc = DDC_MONID;
  463. } else
  464. ddc_line = RADEON_GPIO_CRT2_DDC;
  465. break;
  466. }
  467. if (ddc_line == RADEON_GPIOPAD_MASK) {
  468. i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
  469. i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
  470. i2c.a_clk_reg = RADEON_GPIOPAD_A;
  471. i2c.a_data_reg = RADEON_GPIOPAD_A;
  472. i2c.en_clk_reg = RADEON_GPIOPAD_EN;
  473. i2c.en_data_reg = RADEON_GPIOPAD_EN;
  474. i2c.y_clk_reg = RADEON_GPIOPAD_Y;
  475. i2c.y_data_reg = RADEON_GPIOPAD_Y;
  476. } else if (ddc_line == RADEON_MDGPIO_MASK) {
  477. i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
  478. i2c.mask_data_reg = RADEON_MDGPIO_MASK;
  479. i2c.a_clk_reg = RADEON_MDGPIO_A;
  480. i2c.a_data_reg = RADEON_MDGPIO_A;
  481. i2c.en_clk_reg = RADEON_MDGPIO_EN;
  482. i2c.en_data_reg = RADEON_MDGPIO_EN;
  483. i2c.y_clk_reg = RADEON_MDGPIO_Y;
  484. i2c.y_data_reg = RADEON_MDGPIO_Y;
  485. } else {
  486. i2c.mask_clk_reg = ddc_line;
  487. i2c.mask_data_reg = ddc_line;
  488. i2c.a_clk_reg = ddc_line;
  489. i2c.a_data_reg = ddc_line;
  490. i2c.en_clk_reg = ddc_line;
  491. i2c.en_data_reg = ddc_line;
  492. i2c.y_clk_reg = ddc_line;
  493. i2c.y_data_reg = ddc_line;
  494. }
  495. if (clk_mask && data_mask) {
  496. /* system specific masks */
  497. i2c.mask_clk_mask = clk_mask;
  498. i2c.mask_data_mask = data_mask;
  499. i2c.a_clk_mask = clk_mask;
  500. i2c.a_data_mask = data_mask;
  501. i2c.en_clk_mask = clk_mask;
  502. i2c.en_data_mask = data_mask;
  503. i2c.y_clk_mask = clk_mask;
  504. i2c.y_data_mask = data_mask;
  505. } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
  506. (ddc_line == RADEON_MDGPIO_MASK)) {
  507. /* default gpiopad masks */
  508. i2c.mask_clk_mask = (0x20 << 8);
  509. i2c.mask_data_mask = 0x80;
  510. i2c.a_clk_mask = (0x20 << 8);
  511. i2c.a_data_mask = 0x80;
  512. i2c.en_clk_mask = (0x20 << 8);
  513. i2c.en_data_mask = 0x80;
  514. i2c.y_clk_mask = (0x20 << 8);
  515. i2c.y_data_mask = 0x80;
  516. } else {
  517. /* default masks for ddc pads */
  518. i2c.mask_clk_mask = RADEON_GPIO_MASK_1;
  519. i2c.mask_data_mask = RADEON_GPIO_MASK_0;
  520. i2c.a_clk_mask = RADEON_GPIO_A_1;
  521. i2c.a_data_mask = RADEON_GPIO_A_0;
  522. i2c.en_clk_mask = RADEON_GPIO_EN_1;
  523. i2c.en_data_mask = RADEON_GPIO_EN_0;
  524. i2c.y_clk_mask = RADEON_GPIO_Y_1;
  525. i2c.y_data_mask = RADEON_GPIO_Y_0;
  526. }
  527. switch (rdev->family) {
  528. case CHIP_R100:
  529. case CHIP_RV100:
  530. case CHIP_RS100:
  531. case CHIP_RV200:
  532. case CHIP_RS200:
  533. case CHIP_RS300:
  534. switch (ddc_line) {
  535. case RADEON_GPIO_DVI_DDC:
  536. i2c.hw_capable = true;
  537. break;
  538. default:
  539. i2c.hw_capable = false;
  540. break;
  541. }
  542. break;
  543. case CHIP_R200:
  544. switch (ddc_line) {
  545. case RADEON_GPIO_DVI_DDC:
  546. case RADEON_GPIO_MONID:
  547. i2c.hw_capable = true;
  548. break;
  549. default:
  550. i2c.hw_capable = false;
  551. break;
  552. }
  553. break;
  554. case CHIP_RV250:
  555. case CHIP_RV280:
  556. switch (ddc_line) {
  557. case RADEON_GPIO_VGA_DDC:
  558. case RADEON_GPIO_DVI_DDC:
  559. case RADEON_GPIO_CRT2_DDC:
  560. i2c.hw_capable = true;
  561. break;
  562. default:
  563. i2c.hw_capable = false;
  564. break;
  565. }
  566. break;
  567. case CHIP_R300:
  568. case CHIP_R350:
  569. switch (ddc_line) {
  570. case RADEON_GPIO_VGA_DDC:
  571. case RADEON_GPIO_DVI_DDC:
  572. i2c.hw_capable = true;
  573. break;
  574. default:
  575. i2c.hw_capable = false;
  576. break;
  577. }
  578. break;
  579. case CHIP_RV350:
  580. case CHIP_RV380:
  581. case CHIP_RS400:
  582. case CHIP_RS480:
  583. switch (ddc_line) {
  584. case RADEON_GPIO_VGA_DDC:
  585. case RADEON_GPIO_DVI_DDC:
  586. i2c.hw_capable = true;
  587. break;
  588. case RADEON_GPIO_MONID:
  589. /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
  590. * reliably on some pre-r4xx hardware; not sure why.
  591. */
  592. i2c.hw_capable = false;
  593. break;
  594. default:
  595. i2c.hw_capable = false;
  596. break;
  597. }
  598. break;
  599. default:
  600. i2c.hw_capable = false;
  601. break;
  602. }
  603. i2c.mm_i2c = false;
  604. i2c.i2c_id = ddc;
  605. i2c.hpd = RADEON_HPD_NONE;
  606. if (ddc_line)
  607. i2c.valid = true;
  608. else
  609. i2c.valid = false;
  610. return i2c;
  611. }
  612. static struct radeon_i2c_bus_rec radeon_combios_get_i2c_info_from_table(struct radeon_device *rdev)
  613. {
  614. struct drm_device *dev = rdev->ddev;
  615. struct radeon_i2c_bus_rec i2c;
  616. u16 offset;
  617. u8 id, blocks, clk, data;
  618. int i;
  619. i2c.valid = false;
  620. offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
  621. if (offset) {
  622. blocks = RBIOS8(offset + 2);
  623. for (i = 0; i < blocks; i++) {
  624. id = RBIOS8(offset + 3 + (i * 5) + 0);
  625. if (id == 136) {
  626. clk = RBIOS8(offset + 3 + (i * 5) + 3);
  627. data = RBIOS8(offset + 3 + (i * 5) + 4);
  628. /* gpiopad */
  629. i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
  630. (1 << clk), (1 << data));
  631. break;
  632. }
  633. }
  634. }
  635. return i2c;
  636. }
  637. void radeon_combios_i2c_init(struct radeon_device *rdev)
  638. {
  639. struct drm_device *dev = rdev->ddev;
  640. struct radeon_i2c_bus_rec i2c;
  641. /* actual hw pads
  642. * r1xx/rs2xx/rs3xx
  643. * 0x60, 0x64, 0x68, 0x6c, gpiopads, mm
  644. * r200
  645. * 0x60, 0x64, 0x68, mm
  646. * r300/r350
  647. * 0x60, 0x64, mm
  648. * rv2xx/rv3xx/rs4xx
  649. * 0x60, 0x64, 0x68, gpiopads, mm
  650. */
  651. /* 0x60 */
  652. i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  653. rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
  654. /* 0x64 */
  655. i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  656. rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
  657. /* mm i2c */
  658. i2c.valid = true;
  659. i2c.hw_capable = true;
  660. i2c.mm_i2c = true;
  661. i2c.i2c_id = 0xa0;
  662. rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
  663. if (rdev->family == CHIP_R300 ||
  664. rdev->family == CHIP_R350) {
  665. /* only 2 sw i2c pads */
  666. } else if (rdev->family == CHIP_RS300 ||
  667. rdev->family == CHIP_RS400 ||
  668. rdev->family == CHIP_RS480) {
  669. /* 0x68 */
  670. i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  671. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  672. /* gpiopad */
  673. i2c = radeon_combios_get_i2c_info_from_table(rdev);
  674. if (i2c.valid)
  675. rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
  676. } else if ((rdev->family == CHIP_R200) ||
  677. (rdev->family >= CHIP_R300)) {
  678. /* 0x68 */
  679. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  680. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  681. } else {
  682. /* 0x68 */
  683. i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  684. rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
  685. /* 0x6c */
  686. i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
  687. rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
  688. }
  689. }
  690. bool radeon_combios_get_clock_info(struct drm_device *dev)
  691. {
  692. struct radeon_device *rdev = dev->dev_private;
  693. uint16_t pll_info;
  694. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  695. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  696. struct radeon_pll *spll = &rdev->clock.spll;
  697. struct radeon_pll *mpll = &rdev->clock.mpll;
  698. int8_t rev;
  699. uint16_t sclk, mclk;
  700. pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
  701. if (pll_info) {
  702. rev = RBIOS8(pll_info);
  703. /* pixel clocks */
  704. p1pll->reference_freq = RBIOS16(pll_info + 0xe);
  705. p1pll->reference_div = RBIOS16(pll_info + 0x10);
  706. p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
  707. p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
  708. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  709. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  710. if (rev > 9) {
  711. p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
  712. p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
  713. } else {
  714. p1pll->pll_in_min = 40;
  715. p1pll->pll_in_max = 500;
  716. }
  717. *p2pll = *p1pll;
  718. /* system clock */
  719. spll->reference_freq = RBIOS16(pll_info + 0x1a);
  720. spll->reference_div = RBIOS16(pll_info + 0x1c);
  721. spll->pll_out_min = RBIOS32(pll_info + 0x1e);
  722. spll->pll_out_max = RBIOS32(pll_info + 0x22);
  723. if (rev > 10) {
  724. spll->pll_in_min = RBIOS32(pll_info + 0x48);
  725. spll->pll_in_max = RBIOS32(pll_info + 0x4c);
  726. } else {
  727. /* ??? */
  728. spll->pll_in_min = 40;
  729. spll->pll_in_max = 500;
  730. }
  731. /* memory clock */
  732. mpll->reference_freq = RBIOS16(pll_info + 0x26);
  733. mpll->reference_div = RBIOS16(pll_info + 0x28);
  734. mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
  735. mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
  736. if (rev > 10) {
  737. mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
  738. mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
  739. } else {
  740. /* ??? */
  741. mpll->pll_in_min = 40;
  742. mpll->pll_in_max = 500;
  743. }
  744. /* default sclk/mclk */
  745. sclk = RBIOS16(pll_info + 0xa);
  746. mclk = RBIOS16(pll_info + 0x8);
  747. if (sclk == 0)
  748. sclk = 200 * 100;
  749. if (mclk == 0)
  750. mclk = 200 * 100;
  751. rdev->clock.default_sclk = sclk;
  752. rdev->clock.default_mclk = mclk;
  753. if (RBIOS32(pll_info + 0x16))
  754. rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
  755. else
  756. rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
  757. return true;
  758. }
  759. return false;
  760. }
  761. bool radeon_combios_sideport_present(struct radeon_device *rdev)
  762. {
  763. struct drm_device *dev = rdev->ddev;
  764. u16 igp_info;
  765. /* sideport is AMD only */
  766. if (rdev->family == CHIP_RS400)
  767. return false;
  768. igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
  769. if (igp_info) {
  770. if (RBIOS16(igp_info + 0x4))
  771. return true;
  772. }
  773. return false;
  774. }
  775. static const uint32_t default_primarydac_adj[CHIP_LAST] = {
  776. 0x00000808, /* r100 */
  777. 0x00000808, /* rv100 */
  778. 0x00000808, /* rs100 */
  779. 0x00000808, /* rv200 */
  780. 0x00000808, /* rs200 */
  781. 0x00000808, /* r200 */
  782. 0x00000808, /* rv250 */
  783. 0x00000000, /* rs300 */
  784. 0x00000808, /* rv280 */
  785. 0x00000808, /* r300 */
  786. 0x00000808, /* r350 */
  787. 0x00000808, /* rv350 */
  788. 0x00000808, /* rv380 */
  789. 0x00000808, /* r420 */
  790. 0x00000808, /* r423 */
  791. 0x00000808, /* rv410 */
  792. 0x00000000, /* rs400 */
  793. 0x00000000, /* rs480 */
  794. };
  795. static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
  796. struct radeon_encoder_primary_dac *p_dac)
  797. {
  798. p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
  799. return;
  800. }
  801. struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
  802. radeon_encoder
  803. *encoder)
  804. {
  805. struct drm_device *dev = encoder->base.dev;
  806. struct radeon_device *rdev = dev->dev_private;
  807. uint16_t dac_info;
  808. uint8_t rev, bg, dac;
  809. struct radeon_encoder_primary_dac *p_dac = NULL;
  810. int found = 0;
  811. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
  812. GFP_KERNEL);
  813. if (!p_dac)
  814. return NULL;
  815. /* check CRT table */
  816. dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  817. if (dac_info) {
  818. rev = RBIOS8(dac_info) & 0x3;
  819. if (rev < 2) {
  820. bg = RBIOS8(dac_info + 0x2) & 0xf;
  821. dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
  822. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  823. } else {
  824. bg = RBIOS8(dac_info + 0x2) & 0xf;
  825. dac = RBIOS8(dac_info + 0x3) & 0xf;
  826. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  827. }
  828. /* if the values are zeros, use the table */
  829. if ((dac == 0) || (bg == 0))
  830. found = 0;
  831. else
  832. found = 1;
  833. }
  834. /* quirks */
  835. /* Radeon 7000 (RV100) */
  836. if (((rdev->pdev->device == 0x5159) &&
  837. (rdev->pdev->subsystem_vendor == 0x174B) &&
  838. (rdev->pdev->subsystem_device == 0x7c28)) ||
  839. /* Radeon 9100 (R200) */
  840. ((rdev->pdev->device == 0x514D) &&
  841. (rdev->pdev->subsystem_vendor == 0x174B) &&
  842. (rdev->pdev->subsystem_device == 0x7149))) {
  843. /* vbios value is bad, use the default */
  844. found = 0;
  845. }
  846. if (!found) /* fallback to defaults */
  847. radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
  848. return p_dac;
  849. }
  850. enum radeon_tv_std
  851. radeon_combios_get_tv_info(struct radeon_device *rdev)
  852. {
  853. struct drm_device *dev = rdev->ddev;
  854. uint16_t tv_info;
  855. enum radeon_tv_std tv_std = TV_STD_NTSC;
  856. tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  857. if (tv_info) {
  858. if (RBIOS8(tv_info + 6) == 'T') {
  859. switch (RBIOS8(tv_info + 7) & 0xf) {
  860. case 1:
  861. tv_std = TV_STD_NTSC;
  862. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  863. break;
  864. case 2:
  865. tv_std = TV_STD_PAL;
  866. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  867. break;
  868. case 3:
  869. tv_std = TV_STD_PAL_M;
  870. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  871. break;
  872. case 4:
  873. tv_std = TV_STD_PAL_60;
  874. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  875. break;
  876. case 5:
  877. tv_std = TV_STD_NTSC_J;
  878. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  879. break;
  880. case 6:
  881. tv_std = TV_STD_SCART_PAL;
  882. DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
  883. break;
  884. default:
  885. tv_std = TV_STD_NTSC;
  886. DRM_DEBUG_KMS
  887. ("Unknown TV standard; defaulting to NTSC\n");
  888. break;
  889. }
  890. switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
  891. case 0:
  892. DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
  893. break;
  894. case 1:
  895. DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
  896. break;
  897. case 2:
  898. DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
  899. break;
  900. case 3:
  901. DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
  902. break;
  903. default:
  904. break;
  905. }
  906. }
  907. }
  908. return tv_std;
  909. }
  910. static const uint32_t default_tvdac_adj[CHIP_LAST] = {
  911. 0x00000000, /* r100 */
  912. 0x00280000, /* rv100 */
  913. 0x00000000, /* rs100 */
  914. 0x00880000, /* rv200 */
  915. 0x00000000, /* rs200 */
  916. 0x00000000, /* r200 */
  917. 0x00770000, /* rv250 */
  918. 0x00290000, /* rs300 */
  919. 0x00560000, /* rv280 */
  920. 0x00780000, /* r300 */
  921. 0x00770000, /* r350 */
  922. 0x00780000, /* rv350 */
  923. 0x00780000, /* rv380 */
  924. 0x01080000, /* r420 */
  925. 0x01080000, /* r423 */
  926. 0x01080000, /* rv410 */
  927. 0x00780000, /* rs400 */
  928. 0x00780000, /* rs480 */
  929. };
  930. static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
  931. struct radeon_encoder_tv_dac *tv_dac)
  932. {
  933. tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
  934. if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
  935. tv_dac->ps2_tvdac_adj = 0x00880000;
  936. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  937. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  938. return;
  939. }
  940. struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
  941. radeon_encoder
  942. *encoder)
  943. {
  944. struct drm_device *dev = encoder->base.dev;
  945. struct radeon_device *rdev = dev->dev_private;
  946. uint16_t dac_info;
  947. uint8_t rev, bg, dac;
  948. struct radeon_encoder_tv_dac *tv_dac = NULL;
  949. int found = 0;
  950. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  951. if (!tv_dac)
  952. return NULL;
  953. /* first check TV table */
  954. dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  955. if (dac_info) {
  956. rev = RBIOS8(dac_info + 0x3);
  957. if (rev > 4) {
  958. bg = RBIOS8(dac_info + 0xc) & 0xf;
  959. dac = RBIOS8(dac_info + 0xd) & 0xf;
  960. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  961. bg = RBIOS8(dac_info + 0xe) & 0xf;
  962. dac = RBIOS8(dac_info + 0xf) & 0xf;
  963. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  964. bg = RBIOS8(dac_info + 0x10) & 0xf;
  965. dac = RBIOS8(dac_info + 0x11) & 0xf;
  966. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  967. /* if the values are all zeros, use the table */
  968. if (tv_dac->ps2_tvdac_adj)
  969. found = 1;
  970. } else if (rev > 1) {
  971. bg = RBIOS8(dac_info + 0xc) & 0xf;
  972. dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
  973. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  974. bg = RBIOS8(dac_info + 0xd) & 0xf;
  975. dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
  976. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  977. bg = RBIOS8(dac_info + 0xe) & 0xf;
  978. dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
  979. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  980. /* if the values are all zeros, use the table */
  981. if (tv_dac->ps2_tvdac_adj)
  982. found = 1;
  983. }
  984. tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
  985. }
  986. if (!found) {
  987. /* then check CRT table */
  988. dac_info =
  989. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  990. if (dac_info) {
  991. rev = RBIOS8(dac_info) & 0x3;
  992. if (rev < 2) {
  993. bg = RBIOS8(dac_info + 0x3) & 0xf;
  994. dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
  995. tv_dac->ps2_tvdac_adj =
  996. (bg << 16) | (dac << 20);
  997. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  998. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  999. /* if the values are all zeros, use the table */
  1000. if (tv_dac->ps2_tvdac_adj)
  1001. found = 1;
  1002. } else {
  1003. bg = RBIOS8(dac_info + 0x4) & 0xf;
  1004. dac = RBIOS8(dac_info + 0x5) & 0xf;
  1005. tv_dac->ps2_tvdac_adj =
  1006. (bg << 16) | (dac << 20);
  1007. tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1008. tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
  1009. /* if the values are all zeros, use the table */
  1010. if (tv_dac->ps2_tvdac_adj)
  1011. found = 1;
  1012. }
  1013. } else {
  1014. DRM_INFO("No TV DAC info found in BIOS\n");
  1015. }
  1016. }
  1017. if (!found) /* fallback to defaults */
  1018. radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
  1019. return tv_dac;
  1020. }
  1021. static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
  1022. radeon_device
  1023. *rdev)
  1024. {
  1025. struct radeon_encoder_lvds *lvds = NULL;
  1026. uint32_t fp_vert_stretch, fp_horz_stretch;
  1027. uint32_t ppll_div_sel, ppll_val;
  1028. uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
  1029. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1030. if (!lvds)
  1031. return NULL;
  1032. fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
  1033. fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
  1034. /* These should be fail-safe defaults, fingers crossed */
  1035. lvds->panel_pwr_delay = 200;
  1036. lvds->panel_vcc_delay = 2000;
  1037. lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  1038. lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
  1039. lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
  1040. if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
  1041. lvds->native_mode.vdisplay =
  1042. ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
  1043. RADEON_VERT_PANEL_SHIFT) + 1;
  1044. else
  1045. lvds->native_mode.vdisplay =
  1046. (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
  1047. if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
  1048. lvds->native_mode.hdisplay =
  1049. (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
  1050. RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
  1051. else
  1052. lvds->native_mode.hdisplay =
  1053. ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
  1054. if ((lvds->native_mode.hdisplay < 640) ||
  1055. (lvds->native_mode.vdisplay < 480)) {
  1056. lvds->native_mode.hdisplay = 640;
  1057. lvds->native_mode.vdisplay = 480;
  1058. }
  1059. ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
  1060. ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
  1061. if ((ppll_val & 0x000707ff) == 0x1bb)
  1062. lvds->use_bios_dividers = false;
  1063. else {
  1064. lvds->panel_ref_divider =
  1065. RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  1066. lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
  1067. lvds->panel_fb_divider = ppll_val & 0x7ff;
  1068. if ((lvds->panel_ref_divider != 0) &&
  1069. (lvds->panel_fb_divider > 3))
  1070. lvds->use_bios_dividers = true;
  1071. }
  1072. lvds->panel_vcc_delay = 200;
  1073. DRM_INFO("Panel info derived from registers\n");
  1074. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1075. lvds->native_mode.vdisplay);
  1076. return lvds;
  1077. }
  1078. struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
  1079. *encoder)
  1080. {
  1081. struct drm_device *dev = encoder->base.dev;
  1082. struct radeon_device *rdev = dev->dev_private;
  1083. uint16_t lcd_info;
  1084. uint32_t panel_setup;
  1085. char stmp[30];
  1086. int tmp, i;
  1087. struct radeon_encoder_lvds *lvds = NULL;
  1088. lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  1089. if (lcd_info) {
  1090. lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
  1091. if (!lvds)
  1092. return NULL;
  1093. for (i = 0; i < 24; i++)
  1094. stmp[i] = RBIOS8(lcd_info + i + 1);
  1095. stmp[24] = 0;
  1096. DRM_INFO("Panel ID String: %s\n", stmp);
  1097. lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
  1098. lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
  1099. DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
  1100. lvds->native_mode.vdisplay);
  1101. lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
  1102. lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
  1103. lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
  1104. lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
  1105. lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
  1106. lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
  1107. lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
  1108. lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
  1109. if ((lvds->panel_ref_divider != 0) &&
  1110. (lvds->panel_fb_divider > 3))
  1111. lvds->use_bios_dividers = true;
  1112. panel_setup = RBIOS32(lcd_info + 0x39);
  1113. lvds->lvds_gen_cntl = 0xff00;
  1114. if (panel_setup & 0x1)
  1115. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
  1116. if ((panel_setup >> 4) & 0x1)
  1117. lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
  1118. switch ((panel_setup >> 8) & 0x7) {
  1119. case 0:
  1120. lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
  1121. break;
  1122. case 1:
  1123. lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
  1124. break;
  1125. case 2:
  1126. lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. if ((panel_setup >> 16) & 0x1)
  1132. lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
  1133. if ((panel_setup >> 17) & 0x1)
  1134. lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
  1135. if ((panel_setup >> 18) & 0x1)
  1136. lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
  1137. if ((panel_setup >> 23) & 0x1)
  1138. lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
  1139. lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
  1140. for (i = 0; i < 32; i++) {
  1141. tmp = RBIOS16(lcd_info + 64 + i * 2);
  1142. if (tmp == 0)
  1143. break;
  1144. if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
  1145. (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
  1146. u32 hss = (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
  1147. if (hss > lvds->native_mode.hdisplay)
  1148. hss = (10 - 1) * 8;
  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. hss;
  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. struct radeon_device *rdev = dev->dev_private;
  2084. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  2085. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  2086. if (rdev->pdev->device == 0x515e &&
  2087. rdev->pdev->subsystem_vendor == 0x1014) {
  2088. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  2089. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  2090. return false;
  2091. }
  2092. /* X300 card with extra non-existent DVI port */
  2093. if (rdev->pdev->device == 0x5B60 &&
  2094. rdev->pdev->subsystem_vendor == 0x17af &&
  2095. rdev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  2096. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  2097. return false;
  2098. }
  2099. return true;
  2100. }
  2101. static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
  2102. {
  2103. struct radeon_device *rdev = dev->dev_private;
  2104. /* Acer 5102 has non-existent TV port */
  2105. if (rdev->pdev->device == 0x5975 &&
  2106. rdev->pdev->subsystem_vendor == 0x1025 &&
  2107. rdev->pdev->subsystem_device == 0x009f)
  2108. return false;
  2109. /* HP dc5750 has non-existent TV port */
  2110. if (rdev->pdev->device == 0x5974 &&
  2111. rdev->pdev->subsystem_vendor == 0x103c &&
  2112. rdev->pdev->subsystem_device == 0x280a)
  2113. return false;
  2114. /* MSI S270 has non-existent TV port */
  2115. if (rdev->pdev->device == 0x5955 &&
  2116. rdev->pdev->subsystem_vendor == 0x1462 &&
  2117. rdev->pdev->subsystem_device == 0x0131)
  2118. return false;
  2119. return true;
  2120. }
  2121. static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
  2122. {
  2123. struct radeon_device *rdev = dev->dev_private;
  2124. uint32_t ext_tmds_info;
  2125. if (rdev->flags & RADEON_IS_IGP) {
  2126. if (is_dvi_d)
  2127. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2128. else
  2129. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2130. }
  2131. ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2132. if (ext_tmds_info) {
  2133. uint8_t rev = RBIOS8(ext_tmds_info);
  2134. uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
  2135. if (rev >= 3) {
  2136. if (is_dvi_d)
  2137. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2138. else
  2139. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2140. } else {
  2141. if (flags & 1) {
  2142. if (is_dvi_d)
  2143. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  2144. else
  2145. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  2146. }
  2147. }
  2148. }
  2149. if (is_dvi_d)
  2150. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  2151. else
  2152. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2153. }
  2154. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  2155. {
  2156. struct radeon_device *rdev = dev->dev_private;
  2157. uint32_t conn_info, entry, devices;
  2158. uint16_t tmp, connector_object_id;
  2159. enum radeon_combios_ddc ddc_type;
  2160. enum radeon_combios_connector connector;
  2161. int i = 0;
  2162. struct radeon_i2c_bus_rec ddc_i2c;
  2163. struct radeon_hpd hpd;
  2164. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  2165. if (conn_info) {
  2166. for (i = 0; i < 4; i++) {
  2167. entry = conn_info + 2 + i * 2;
  2168. if (!RBIOS16(entry))
  2169. break;
  2170. tmp = RBIOS16(entry);
  2171. connector = (tmp >> 12) & 0xf;
  2172. ddc_type = (tmp >> 8) & 0xf;
  2173. if (ddc_type == 5)
  2174. ddc_i2c = radeon_combios_get_i2c_info_from_table(rdev);
  2175. else
  2176. ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2177. switch (connector) {
  2178. case CONNECTOR_PROPRIETARY_LEGACY:
  2179. case CONNECTOR_DVI_I_LEGACY:
  2180. case CONNECTOR_DVI_D_LEGACY:
  2181. if ((tmp >> 4) & 0x1)
  2182. hpd.hpd = RADEON_HPD_2;
  2183. else
  2184. hpd.hpd = RADEON_HPD_1;
  2185. break;
  2186. default:
  2187. hpd.hpd = RADEON_HPD_NONE;
  2188. break;
  2189. }
  2190. if (!radeon_apply_legacy_quirks(dev, i, &connector,
  2191. &ddc_i2c, &hpd))
  2192. continue;
  2193. switch (connector) {
  2194. case CONNECTOR_PROPRIETARY_LEGACY:
  2195. if ((tmp >> 4) & 0x1)
  2196. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2197. else
  2198. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2199. radeon_add_legacy_encoder(dev,
  2200. radeon_get_encoder_enum
  2201. (dev, devices, 0),
  2202. devices);
  2203. radeon_add_legacy_connector(dev, i, devices,
  2204. legacy_connector_convert
  2205. [connector],
  2206. &ddc_i2c,
  2207. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  2208. &hpd);
  2209. break;
  2210. case CONNECTOR_CRT_LEGACY:
  2211. if (tmp & 0x1) {
  2212. devices = ATOM_DEVICE_CRT2_SUPPORT;
  2213. radeon_add_legacy_encoder(dev,
  2214. radeon_get_encoder_enum
  2215. (dev,
  2216. ATOM_DEVICE_CRT2_SUPPORT,
  2217. 2),
  2218. ATOM_DEVICE_CRT2_SUPPORT);
  2219. } else {
  2220. devices = ATOM_DEVICE_CRT1_SUPPORT;
  2221. radeon_add_legacy_encoder(dev,
  2222. radeon_get_encoder_enum
  2223. (dev,
  2224. ATOM_DEVICE_CRT1_SUPPORT,
  2225. 1),
  2226. ATOM_DEVICE_CRT1_SUPPORT);
  2227. }
  2228. radeon_add_legacy_connector(dev,
  2229. i,
  2230. devices,
  2231. legacy_connector_convert
  2232. [connector],
  2233. &ddc_i2c,
  2234. CONNECTOR_OBJECT_ID_VGA,
  2235. &hpd);
  2236. break;
  2237. case CONNECTOR_DVI_I_LEGACY:
  2238. devices = 0;
  2239. if (tmp & 0x1) {
  2240. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  2241. radeon_add_legacy_encoder(dev,
  2242. radeon_get_encoder_enum
  2243. (dev,
  2244. ATOM_DEVICE_CRT2_SUPPORT,
  2245. 2),
  2246. ATOM_DEVICE_CRT2_SUPPORT);
  2247. } else {
  2248. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  2249. radeon_add_legacy_encoder(dev,
  2250. radeon_get_encoder_enum
  2251. (dev,
  2252. ATOM_DEVICE_CRT1_SUPPORT,
  2253. 1),
  2254. ATOM_DEVICE_CRT1_SUPPORT);
  2255. }
  2256. /* RV100 board with external TDMS bit mis-set.
  2257. * Actually uses internal TMDS, clear the bit.
  2258. */
  2259. if (rdev->pdev->device == 0x5159 &&
  2260. rdev->pdev->subsystem_vendor == 0x1014 &&
  2261. rdev->pdev->subsystem_device == 0x029A) {
  2262. tmp &= ~(1 << 4);
  2263. }
  2264. if ((tmp >> 4) & 0x1) {
  2265. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  2266. radeon_add_legacy_encoder(dev,
  2267. radeon_get_encoder_enum
  2268. (dev,
  2269. ATOM_DEVICE_DFP2_SUPPORT,
  2270. 0),
  2271. ATOM_DEVICE_DFP2_SUPPORT);
  2272. connector_object_id = combios_check_dl_dvi(dev, 0);
  2273. } else {
  2274. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  2275. radeon_add_legacy_encoder(dev,
  2276. radeon_get_encoder_enum
  2277. (dev,
  2278. ATOM_DEVICE_DFP1_SUPPORT,
  2279. 0),
  2280. ATOM_DEVICE_DFP1_SUPPORT);
  2281. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2282. }
  2283. radeon_add_legacy_connector(dev,
  2284. i,
  2285. devices,
  2286. legacy_connector_convert
  2287. [connector],
  2288. &ddc_i2c,
  2289. connector_object_id,
  2290. &hpd);
  2291. break;
  2292. case CONNECTOR_DVI_D_LEGACY:
  2293. if ((tmp >> 4) & 0x1) {
  2294. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2295. connector_object_id = combios_check_dl_dvi(dev, 1);
  2296. } else {
  2297. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2298. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2299. }
  2300. radeon_add_legacy_encoder(dev,
  2301. radeon_get_encoder_enum
  2302. (dev, devices, 0),
  2303. devices);
  2304. radeon_add_legacy_connector(dev, i, devices,
  2305. legacy_connector_convert
  2306. [connector],
  2307. &ddc_i2c,
  2308. connector_object_id,
  2309. &hpd);
  2310. break;
  2311. case CONNECTOR_CTV_LEGACY:
  2312. case CONNECTOR_STV_LEGACY:
  2313. radeon_add_legacy_encoder(dev,
  2314. radeon_get_encoder_enum
  2315. (dev,
  2316. ATOM_DEVICE_TV1_SUPPORT,
  2317. 2),
  2318. ATOM_DEVICE_TV1_SUPPORT);
  2319. radeon_add_legacy_connector(dev, i,
  2320. ATOM_DEVICE_TV1_SUPPORT,
  2321. legacy_connector_convert
  2322. [connector],
  2323. &ddc_i2c,
  2324. CONNECTOR_OBJECT_ID_SVIDEO,
  2325. &hpd);
  2326. break;
  2327. default:
  2328. DRM_ERROR("Unknown connector type: %d\n",
  2329. connector);
  2330. continue;
  2331. }
  2332. }
  2333. } else {
  2334. uint16_t tmds_info =
  2335. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  2336. if (tmds_info) {
  2337. DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
  2338. radeon_add_legacy_encoder(dev,
  2339. radeon_get_encoder_enum(dev,
  2340. ATOM_DEVICE_CRT1_SUPPORT,
  2341. 1),
  2342. ATOM_DEVICE_CRT1_SUPPORT);
  2343. radeon_add_legacy_encoder(dev,
  2344. radeon_get_encoder_enum(dev,
  2345. ATOM_DEVICE_DFP1_SUPPORT,
  2346. 0),
  2347. ATOM_DEVICE_DFP1_SUPPORT);
  2348. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
  2349. hpd.hpd = RADEON_HPD_1;
  2350. radeon_add_legacy_connector(dev,
  2351. 0,
  2352. ATOM_DEVICE_CRT1_SUPPORT |
  2353. ATOM_DEVICE_DFP1_SUPPORT,
  2354. DRM_MODE_CONNECTOR_DVII,
  2355. &ddc_i2c,
  2356. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2357. &hpd);
  2358. } else {
  2359. uint16_t crt_info =
  2360. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  2361. DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
  2362. if (crt_info) {
  2363. radeon_add_legacy_encoder(dev,
  2364. radeon_get_encoder_enum(dev,
  2365. ATOM_DEVICE_CRT1_SUPPORT,
  2366. 1),
  2367. ATOM_DEVICE_CRT1_SUPPORT);
  2368. ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
  2369. hpd.hpd = RADEON_HPD_NONE;
  2370. radeon_add_legacy_connector(dev,
  2371. 0,
  2372. ATOM_DEVICE_CRT1_SUPPORT,
  2373. DRM_MODE_CONNECTOR_VGA,
  2374. &ddc_i2c,
  2375. CONNECTOR_OBJECT_ID_VGA,
  2376. &hpd);
  2377. } else {
  2378. DRM_DEBUG_KMS("No connector info found\n");
  2379. return false;
  2380. }
  2381. }
  2382. }
  2383. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  2384. uint16_t lcd_info =
  2385. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  2386. if (lcd_info) {
  2387. uint16_t lcd_ddc_info =
  2388. combios_get_table_offset(dev,
  2389. COMBIOS_LCD_DDC_INFO_TABLE);
  2390. radeon_add_legacy_encoder(dev,
  2391. radeon_get_encoder_enum(dev,
  2392. ATOM_DEVICE_LCD1_SUPPORT,
  2393. 0),
  2394. ATOM_DEVICE_LCD1_SUPPORT);
  2395. if (lcd_ddc_info) {
  2396. ddc_type = RBIOS8(lcd_ddc_info + 2);
  2397. switch (ddc_type) {
  2398. case DDC_LCD:
  2399. ddc_i2c =
  2400. combios_setup_i2c_bus(rdev,
  2401. DDC_LCD,
  2402. RBIOS32(lcd_ddc_info + 3),
  2403. RBIOS32(lcd_ddc_info + 7));
  2404. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2405. break;
  2406. case DDC_GPIO:
  2407. ddc_i2c =
  2408. combios_setup_i2c_bus(rdev,
  2409. DDC_GPIO,
  2410. RBIOS32(lcd_ddc_info + 3),
  2411. RBIOS32(lcd_ddc_info + 7));
  2412. radeon_i2c_add(rdev, &ddc_i2c, "LCD");
  2413. break;
  2414. default:
  2415. ddc_i2c =
  2416. combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
  2417. break;
  2418. }
  2419. DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
  2420. } else
  2421. ddc_i2c.valid = false;
  2422. hpd.hpd = RADEON_HPD_NONE;
  2423. radeon_add_legacy_connector(dev,
  2424. 5,
  2425. ATOM_DEVICE_LCD1_SUPPORT,
  2426. DRM_MODE_CONNECTOR_LVDS,
  2427. &ddc_i2c,
  2428. CONNECTOR_OBJECT_ID_LVDS,
  2429. &hpd);
  2430. }
  2431. }
  2432. /* check TV table */
  2433. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  2434. uint32_t tv_info =
  2435. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  2436. if (tv_info) {
  2437. if (RBIOS8(tv_info + 6) == 'T') {
  2438. if (radeon_apply_legacy_tv_quirks(dev)) {
  2439. hpd.hpd = RADEON_HPD_NONE;
  2440. ddc_i2c.valid = false;
  2441. radeon_add_legacy_encoder(dev,
  2442. radeon_get_encoder_enum
  2443. (dev,
  2444. ATOM_DEVICE_TV1_SUPPORT,
  2445. 2),
  2446. ATOM_DEVICE_TV1_SUPPORT);
  2447. radeon_add_legacy_connector(dev, 6,
  2448. ATOM_DEVICE_TV1_SUPPORT,
  2449. DRM_MODE_CONNECTOR_SVIDEO,
  2450. &ddc_i2c,
  2451. CONNECTOR_OBJECT_ID_SVIDEO,
  2452. &hpd);
  2453. }
  2454. }
  2455. }
  2456. }
  2457. radeon_link_encoder_connector(dev);
  2458. return true;
  2459. }
  2460. static const char *thermal_controller_names[] = {
  2461. "NONE",
  2462. "lm63",
  2463. "adm1032",
  2464. };
  2465. void radeon_combios_get_power_modes(struct radeon_device *rdev)
  2466. {
  2467. struct drm_device *dev = rdev->ddev;
  2468. u16 offset, misc, misc2 = 0;
  2469. u8 rev, tmp;
  2470. int state_index = 0;
  2471. struct radeon_i2c_bus_rec i2c_bus;
  2472. rdev->pm.default_power_state_index = -1;
  2473. /* allocate 2 power states */
  2474. rdev->pm.power_state = kcalloc(2, sizeof(struct radeon_power_state),
  2475. GFP_KERNEL);
  2476. if (rdev->pm.power_state) {
  2477. /* allocate 1 clock mode per state */
  2478. rdev->pm.power_state[0].clock_info =
  2479. kcalloc(1, sizeof(struct radeon_pm_clock_info),
  2480. GFP_KERNEL);
  2481. rdev->pm.power_state[1].clock_info =
  2482. kcalloc(1, sizeof(struct radeon_pm_clock_info),
  2483. GFP_KERNEL);
  2484. if (!rdev->pm.power_state[0].clock_info ||
  2485. !rdev->pm.power_state[1].clock_info)
  2486. goto pm_failed;
  2487. } else
  2488. goto pm_failed;
  2489. /* check for a thermal chip */
  2490. offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
  2491. if (offset) {
  2492. u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
  2493. rev = RBIOS8(offset);
  2494. if (rev == 0) {
  2495. thermal_controller = RBIOS8(offset + 3);
  2496. gpio = RBIOS8(offset + 4) & 0x3f;
  2497. i2c_addr = RBIOS8(offset + 5);
  2498. } else if (rev == 1) {
  2499. thermal_controller = RBIOS8(offset + 4);
  2500. gpio = RBIOS8(offset + 5) & 0x3f;
  2501. i2c_addr = RBIOS8(offset + 6);
  2502. } else if (rev == 2) {
  2503. thermal_controller = RBIOS8(offset + 4);
  2504. gpio = RBIOS8(offset + 5) & 0x3f;
  2505. i2c_addr = RBIOS8(offset + 6);
  2506. clk_bit = RBIOS8(offset + 0xa);
  2507. data_bit = RBIOS8(offset + 0xb);
  2508. }
  2509. if ((thermal_controller > 0) && (thermal_controller < 3)) {
  2510. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2511. thermal_controller_names[thermal_controller],
  2512. i2c_addr >> 1);
  2513. if (gpio == DDC_LCD) {
  2514. /* MM i2c */
  2515. i2c_bus.valid = true;
  2516. i2c_bus.hw_capable = true;
  2517. i2c_bus.mm_i2c = true;
  2518. i2c_bus.i2c_id = 0xa0;
  2519. } else if (gpio == DDC_GPIO)
  2520. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
  2521. else
  2522. i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
  2523. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2524. if (rdev->pm.i2c_bus) {
  2525. struct i2c_board_info info = { };
  2526. const char *name = thermal_controller_names[thermal_controller];
  2527. info.addr = i2c_addr >> 1;
  2528. strlcpy(info.type, name, sizeof(info.type));
  2529. i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
  2530. }
  2531. }
  2532. } else {
  2533. /* boards with a thermal chip, but no overdrive table */
  2534. /* Asus 9600xt has an f75375 on the monid bus */
  2535. if ((rdev->pdev->device == 0x4152) &&
  2536. (rdev->pdev->subsystem_vendor == 0x1043) &&
  2537. (rdev->pdev->subsystem_device == 0xc002)) {
  2538. i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
  2539. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2540. if (rdev->pm.i2c_bus) {
  2541. struct i2c_board_info info = { };
  2542. const char *name = "f75375";
  2543. info.addr = 0x28;
  2544. strlcpy(info.type, name, sizeof(info.type));
  2545. i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
  2546. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  2547. name, info.addr);
  2548. }
  2549. }
  2550. }
  2551. if (rdev->flags & RADEON_IS_MOBILITY) {
  2552. offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
  2553. if (offset) {
  2554. rev = RBIOS8(offset);
  2555. /* power mode 0 tends to be the only valid one */
  2556. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2557. rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
  2558. rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
  2559. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  2560. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  2561. goto default_mode;
  2562. rdev->pm.power_state[state_index].type =
  2563. POWER_STATE_TYPE_BATTERY;
  2564. misc = RBIOS16(offset + 0x5 + 0x0);
  2565. if (rev > 4)
  2566. misc2 = RBIOS16(offset + 0x5 + 0xe);
  2567. rdev->pm.power_state[state_index].misc = misc;
  2568. rdev->pm.power_state[state_index].misc2 = misc2;
  2569. if (misc & 0x4) {
  2570. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
  2571. if (misc & 0x8)
  2572. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2573. true;
  2574. else
  2575. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2576. false;
  2577. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
  2578. if (rev < 6) {
  2579. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2580. RBIOS16(offset + 0x5 + 0xb) * 4;
  2581. tmp = RBIOS8(offset + 0x5 + 0xd);
  2582. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2583. } else {
  2584. u8 entries = RBIOS8(offset + 0x5 + 0xb);
  2585. u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
  2586. if (entries && voltage_table_offset) {
  2587. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2588. RBIOS16(voltage_table_offset) * 4;
  2589. tmp = RBIOS8(voltage_table_offset + 0x2);
  2590. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2591. } else
  2592. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
  2593. }
  2594. switch ((misc2 & 0x700) >> 8) {
  2595. case 0:
  2596. default:
  2597. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
  2598. break;
  2599. case 1:
  2600. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
  2601. break;
  2602. case 2:
  2603. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
  2604. break;
  2605. case 3:
  2606. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
  2607. break;
  2608. case 4:
  2609. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
  2610. break;
  2611. }
  2612. } else
  2613. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2614. if (rev > 6)
  2615. rdev->pm.power_state[state_index].pcie_lanes =
  2616. RBIOS8(offset + 0x5 + 0x10);
  2617. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2618. state_index++;
  2619. } else {
  2620. /* XXX figure out some good default low power mode for mobility cards w/out power tables */
  2621. }
  2622. } else {
  2623. /* XXX figure out some good default low power mode for desktop cards */
  2624. }
  2625. default_mode:
  2626. /* add the default mode */
  2627. rdev->pm.power_state[state_index].type =
  2628. POWER_STATE_TYPE_DEFAULT;
  2629. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2630. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2631. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2632. rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
  2633. if ((state_index > 0) &&
  2634. (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
  2635. rdev->pm.power_state[state_index].clock_info[0].voltage =
  2636. rdev->pm.power_state[0].clock_info[0].voltage;
  2637. else
  2638. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2639. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2640. rdev->pm.power_state[state_index].flags = 0;
  2641. rdev->pm.default_power_state_index = state_index;
  2642. rdev->pm.num_power_states = state_index + 1;
  2643. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2644. rdev->pm.current_clock_mode_index = 0;
  2645. return;
  2646. pm_failed:
  2647. rdev->pm.default_power_state_index = state_index;
  2648. rdev->pm.num_power_states = 0;
  2649. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2650. rdev->pm.current_clock_mode_index = 0;
  2651. }
  2652. void radeon_external_tmds_setup(struct drm_encoder *encoder)
  2653. {
  2654. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2655. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2656. if (!tmds)
  2657. return;
  2658. switch (tmds->dvo_chip) {
  2659. case DVO_SIL164:
  2660. /* sil 164 */
  2661. radeon_i2c_put_byte(tmds->i2c_bus,
  2662. tmds->slave_addr,
  2663. 0x08, 0x30);
  2664. radeon_i2c_put_byte(tmds->i2c_bus,
  2665. tmds->slave_addr,
  2666. 0x09, 0x00);
  2667. radeon_i2c_put_byte(tmds->i2c_bus,
  2668. tmds->slave_addr,
  2669. 0x0a, 0x90);
  2670. radeon_i2c_put_byte(tmds->i2c_bus,
  2671. tmds->slave_addr,
  2672. 0x0c, 0x89);
  2673. radeon_i2c_put_byte(tmds->i2c_bus,
  2674. tmds->slave_addr,
  2675. 0x08, 0x3b);
  2676. break;
  2677. case DVO_SIL1178:
  2678. /* sil 1178 - untested */
  2679. /*
  2680. * 0x0f, 0x44
  2681. * 0x0f, 0x4c
  2682. * 0x0e, 0x01
  2683. * 0x0a, 0x80
  2684. * 0x09, 0x30
  2685. * 0x0c, 0xc9
  2686. * 0x0d, 0x70
  2687. * 0x08, 0x32
  2688. * 0x08, 0x33
  2689. */
  2690. break;
  2691. default:
  2692. break;
  2693. }
  2694. }
  2695. bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
  2696. {
  2697. struct drm_device *dev = encoder->dev;
  2698. struct radeon_device *rdev = dev->dev_private;
  2699. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2700. uint16_t offset;
  2701. uint8_t blocks, slave_addr, rev;
  2702. uint32_t index, id;
  2703. uint32_t reg, val, and_mask, or_mask;
  2704. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2705. if (!tmds)
  2706. return false;
  2707. if (rdev->flags & RADEON_IS_IGP) {
  2708. offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
  2709. rev = RBIOS8(offset);
  2710. if (offset) {
  2711. rev = RBIOS8(offset);
  2712. if (rev > 1) {
  2713. blocks = RBIOS8(offset + 3);
  2714. index = offset + 4;
  2715. while (blocks > 0) {
  2716. id = RBIOS16(index);
  2717. index += 2;
  2718. switch (id >> 13) {
  2719. case 0:
  2720. reg = (id & 0x1fff) * 4;
  2721. val = RBIOS32(index);
  2722. index += 4;
  2723. WREG32(reg, val);
  2724. break;
  2725. case 2:
  2726. reg = (id & 0x1fff) * 4;
  2727. and_mask = RBIOS32(index);
  2728. index += 4;
  2729. or_mask = RBIOS32(index);
  2730. index += 4;
  2731. val = RREG32(reg);
  2732. val = (val & and_mask) | or_mask;
  2733. WREG32(reg, val);
  2734. break;
  2735. case 3:
  2736. val = RBIOS16(index);
  2737. index += 2;
  2738. udelay(val);
  2739. break;
  2740. case 4:
  2741. val = RBIOS16(index);
  2742. index += 2;
  2743. mdelay(val);
  2744. break;
  2745. case 6:
  2746. slave_addr = id & 0xff;
  2747. slave_addr >>= 1; /* 7 bit addressing */
  2748. index++;
  2749. reg = RBIOS8(index);
  2750. index++;
  2751. val = RBIOS8(index);
  2752. index++;
  2753. radeon_i2c_put_byte(tmds->i2c_bus,
  2754. slave_addr,
  2755. reg, val);
  2756. break;
  2757. default:
  2758. DRM_ERROR("Unknown id %d\n", id >> 13);
  2759. break;
  2760. }
  2761. blocks--;
  2762. }
  2763. return true;
  2764. }
  2765. }
  2766. } else {
  2767. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2768. if (offset) {
  2769. index = offset + 10;
  2770. id = RBIOS16(index);
  2771. while (id != 0xffff) {
  2772. index += 2;
  2773. switch (id >> 13) {
  2774. case 0:
  2775. reg = (id & 0x1fff) * 4;
  2776. val = RBIOS32(index);
  2777. WREG32(reg, val);
  2778. break;
  2779. case 2:
  2780. reg = (id & 0x1fff) * 4;
  2781. and_mask = RBIOS32(index);
  2782. index += 4;
  2783. or_mask = RBIOS32(index);
  2784. index += 4;
  2785. val = RREG32(reg);
  2786. val = (val & and_mask) | or_mask;
  2787. WREG32(reg, val);
  2788. break;
  2789. case 4:
  2790. val = RBIOS16(index);
  2791. index += 2;
  2792. udelay(val);
  2793. break;
  2794. case 5:
  2795. reg = id & 0x1fff;
  2796. and_mask = RBIOS32(index);
  2797. index += 4;
  2798. or_mask = RBIOS32(index);
  2799. index += 4;
  2800. val = RREG32_PLL(reg);
  2801. val = (val & and_mask) | or_mask;
  2802. WREG32_PLL(reg, val);
  2803. break;
  2804. case 6:
  2805. reg = id & 0x1fff;
  2806. val = RBIOS8(index);
  2807. index += 1;
  2808. radeon_i2c_put_byte(tmds->i2c_bus,
  2809. tmds->slave_addr,
  2810. reg, val);
  2811. break;
  2812. default:
  2813. DRM_ERROR("Unknown id %d\n", id >> 13);
  2814. break;
  2815. }
  2816. id = RBIOS16(index);
  2817. }
  2818. return true;
  2819. }
  2820. }
  2821. return false;
  2822. }
  2823. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  2824. {
  2825. struct radeon_device *rdev = dev->dev_private;
  2826. if (offset) {
  2827. while (RBIOS16(offset)) {
  2828. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  2829. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  2830. uint32_t val, and_mask, or_mask;
  2831. uint32_t tmp;
  2832. offset += 2;
  2833. switch (cmd) {
  2834. case 0:
  2835. val = RBIOS32(offset);
  2836. offset += 4;
  2837. WREG32(addr, val);
  2838. break;
  2839. case 1:
  2840. val = RBIOS32(offset);
  2841. offset += 4;
  2842. WREG32(addr, val);
  2843. break;
  2844. case 2:
  2845. and_mask = RBIOS32(offset);
  2846. offset += 4;
  2847. or_mask = RBIOS32(offset);
  2848. offset += 4;
  2849. tmp = RREG32(addr);
  2850. tmp &= and_mask;
  2851. tmp |= or_mask;
  2852. WREG32(addr, tmp);
  2853. break;
  2854. case 3:
  2855. and_mask = RBIOS32(offset);
  2856. offset += 4;
  2857. or_mask = RBIOS32(offset);
  2858. offset += 4;
  2859. tmp = RREG32(addr);
  2860. tmp &= and_mask;
  2861. tmp |= or_mask;
  2862. WREG32(addr, tmp);
  2863. break;
  2864. case 4:
  2865. val = RBIOS16(offset);
  2866. offset += 2;
  2867. udelay(val);
  2868. break;
  2869. case 5:
  2870. val = RBIOS16(offset);
  2871. offset += 2;
  2872. switch (addr) {
  2873. case 8:
  2874. while (val--) {
  2875. if (!
  2876. (RREG32_PLL
  2877. (RADEON_CLK_PWRMGT_CNTL) &
  2878. RADEON_MC_BUSY))
  2879. break;
  2880. }
  2881. break;
  2882. case 9:
  2883. while (val--) {
  2884. if ((RREG32(RADEON_MC_STATUS) &
  2885. RADEON_MC_IDLE))
  2886. break;
  2887. }
  2888. break;
  2889. default:
  2890. break;
  2891. }
  2892. break;
  2893. default:
  2894. break;
  2895. }
  2896. }
  2897. }
  2898. }
  2899. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  2900. {
  2901. struct radeon_device *rdev = dev->dev_private;
  2902. if (offset) {
  2903. while (RBIOS8(offset)) {
  2904. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  2905. uint8_t addr = (RBIOS8(offset) & 0x3f);
  2906. uint32_t val, shift, tmp;
  2907. uint32_t and_mask, or_mask;
  2908. offset++;
  2909. switch (cmd) {
  2910. case 0:
  2911. val = RBIOS32(offset);
  2912. offset += 4;
  2913. WREG32_PLL(addr, val);
  2914. break;
  2915. case 1:
  2916. shift = RBIOS8(offset) * 8;
  2917. offset++;
  2918. and_mask = RBIOS8(offset) << shift;
  2919. and_mask |= ~(0xff << shift);
  2920. offset++;
  2921. or_mask = RBIOS8(offset) << shift;
  2922. offset++;
  2923. tmp = RREG32_PLL(addr);
  2924. tmp &= and_mask;
  2925. tmp |= or_mask;
  2926. WREG32_PLL(addr, tmp);
  2927. break;
  2928. case 2:
  2929. case 3:
  2930. tmp = 1000;
  2931. switch (addr) {
  2932. case 1:
  2933. udelay(150);
  2934. break;
  2935. case 2:
  2936. mdelay(1);
  2937. break;
  2938. case 3:
  2939. while (tmp--) {
  2940. if (!
  2941. (RREG32_PLL
  2942. (RADEON_CLK_PWRMGT_CNTL) &
  2943. RADEON_MC_BUSY))
  2944. break;
  2945. }
  2946. break;
  2947. case 4:
  2948. while (tmp--) {
  2949. if (RREG32_PLL
  2950. (RADEON_CLK_PWRMGT_CNTL) &
  2951. RADEON_DLL_READY)
  2952. break;
  2953. }
  2954. break;
  2955. case 5:
  2956. tmp =
  2957. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  2958. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  2959. #if 0
  2960. uint32_t mclk_cntl =
  2961. RREG32_PLL
  2962. (RADEON_MCLK_CNTL);
  2963. mclk_cntl &= 0xffff0000;
  2964. /*mclk_cntl |= 0x00001111;*//* ??? */
  2965. WREG32_PLL(RADEON_MCLK_CNTL,
  2966. mclk_cntl);
  2967. mdelay(10);
  2968. #endif
  2969. WREG32_PLL
  2970. (RADEON_CLK_PWRMGT_CNTL,
  2971. tmp &
  2972. ~RADEON_CG_NO1_DEBUG_0);
  2973. mdelay(10);
  2974. }
  2975. break;
  2976. default:
  2977. break;
  2978. }
  2979. break;
  2980. default:
  2981. break;
  2982. }
  2983. }
  2984. }
  2985. }
  2986. static void combios_parse_ram_reset_table(struct drm_device *dev,
  2987. uint16_t offset)
  2988. {
  2989. struct radeon_device *rdev = dev->dev_private;
  2990. uint32_t tmp;
  2991. if (offset) {
  2992. uint8_t val = RBIOS8(offset);
  2993. while (val != 0xff) {
  2994. offset++;
  2995. if (val == 0x0f) {
  2996. uint32_t channel_complete_mask;
  2997. if (ASIC_IS_R300(rdev))
  2998. channel_complete_mask =
  2999. R300_MEM_PWRUP_COMPLETE;
  3000. else
  3001. channel_complete_mask =
  3002. RADEON_MEM_PWRUP_COMPLETE;
  3003. tmp = 20000;
  3004. while (tmp--) {
  3005. if ((RREG32(RADEON_MEM_STR_CNTL) &
  3006. channel_complete_mask) ==
  3007. channel_complete_mask)
  3008. break;
  3009. }
  3010. } else {
  3011. uint32_t or_mask = RBIOS16(offset);
  3012. offset += 2;
  3013. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  3014. tmp &= RADEON_SDRAM_MODE_MASK;
  3015. tmp |= or_mask;
  3016. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  3017. or_mask = val << 24;
  3018. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  3019. tmp &= RADEON_B3MEM_RESET_MASK;
  3020. tmp |= or_mask;
  3021. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  3022. }
  3023. val = RBIOS8(offset);
  3024. }
  3025. }
  3026. }
  3027. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  3028. int mem_addr_mapping)
  3029. {
  3030. struct radeon_device *rdev = dev->dev_private;
  3031. uint32_t mem_cntl;
  3032. uint32_t mem_size;
  3033. uint32_t addr = 0;
  3034. mem_cntl = RREG32(RADEON_MEM_CNTL);
  3035. if (mem_cntl & RV100_HALF_MODE)
  3036. ram /= 2;
  3037. mem_size = ram;
  3038. mem_cntl &= ~(0xff << 8);
  3039. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  3040. WREG32(RADEON_MEM_CNTL, mem_cntl);
  3041. RREG32(RADEON_MEM_CNTL);
  3042. /* sdram reset ? */
  3043. /* something like this???? */
  3044. while (ram--) {
  3045. addr = ram * 1024 * 1024;
  3046. /* write to each page */
  3047. WREG32_IDX((addr) | RADEON_MM_APER, 0xdeadbeef);
  3048. /* read back and verify */
  3049. if (RREG32_IDX((addr) | RADEON_MM_APER) != 0xdeadbeef)
  3050. return 0;
  3051. }
  3052. return mem_size;
  3053. }
  3054. static void combios_write_ram_size(struct drm_device *dev)
  3055. {
  3056. struct radeon_device *rdev = dev->dev_private;
  3057. uint8_t rev;
  3058. uint16_t offset;
  3059. uint32_t mem_size = 0;
  3060. uint32_t mem_cntl = 0;
  3061. /* should do something smarter here I guess... */
  3062. if (rdev->flags & RADEON_IS_IGP)
  3063. return;
  3064. /* first check detected mem table */
  3065. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  3066. if (offset) {
  3067. rev = RBIOS8(offset);
  3068. if (rev < 3) {
  3069. mem_cntl = RBIOS32(offset + 1);
  3070. mem_size = RBIOS16(offset + 5);
  3071. if ((rdev->family < CHIP_R200) &&
  3072. !ASIC_IS_RN50(rdev))
  3073. WREG32(RADEON_MEM_CNTL, mem_cntl);
  3074. }
  3075. }
  3076. if (!mem_size) {
  3077. offset =
  3078. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  3079. if (offset) {
  3080. rev = RBIOS8(offset - 1);
  3081. if (rev < 1) {
  3082. if ((rdev->family < CHIP_R200)
  3083. && !ASIC_IS_RN50(rdev)) {
  3084. int ram = 0;
  3085. int mem_addr_mapping = 0;
  3086. while (RBIOS8(offset)) {
  3087. ram = RBIOS8(offset);
  3088. mem_addr_mapping =
  3089. RBIOS8(offset + 1);
  3090. if (mem_addr_mapping != 0x25)
  3091. ram *= 2;
  3092. mem_size =
  3093. combios_detect_ram(dev, ram,
  3094. mem_addr_mapping);
  3095. if (mem_size)
  3096. break;
  3097. offset += 2;
  3098. }
  3099. } else
  3100. mem_size = RBIOS8(offset);
  3101. } else {
  3102. mem_size = RBIOS8(offset);
  3103. mem_size *= 2; /* convert to MB */
  3104. }
  3105. }
  3106. }
  3107. mem_size *= (1024 * 1024); /* convert to bytes */
  3108. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  3109. }
  3110. void radeon_combios_asic_init(struct drm_device *dev)
  3111. {
  3112. struct radeon_device *rdev = dev->dev_private;
  3113. uint16_t table;
  3114. /* port hardcoded mac stuff from radeonfb */
  3115. if (rdev->bios == NULL)
  3116. return;
  3117. /* ASIC INIT 1 */
  3118. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  3119. if (table)
  3120. combios_parse_mmio_table(dev, table);
  3121. /* PLL INIT */
  3122. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  3123. if (table)
  3124. combios_parse_pll_table(dev, table);
  3125. /* ASIC INIT 2 */
  3126. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  3127. if (table)
  3128. combios_parse_mmio_table(dev, table);
  3129. if (!(rdev->flags & RADEON_IS_IGP)) {
  3130. /* ASIC INIT 4 */
  3131. table =
  3132. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  3133. if (table)
  3134. combios_parse_mmio_table(dev, table);
  3135. /* RAM RESET */
  3136. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  3137. if (table)
  3138. combios_parse_ram_reset_table(dev, table);
  3139. /* ASIC INIT 3 */
  3140. table =
  3141. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  3142. if (table)
  3143. combios_parse_mmio_table(dev, table);
  3144. /* write CONFIG_MEMSIZE */
  3145. combios_write_ram_size(dev);
  3146. }
  3147. /* quirk for rs4xx HP nx6125 laptop to make it resume
  3148. * - it hangs on resume inside the dynclk 1 table.
  3149. */
  3150. if (rdev->family == CHIP_RS480 &&
  3151. rdev->pdev->subsystem_vendor == 0x103c &&
  3152. rdev->pdev->subsystem_device == 0x308b)
  3153. return;
  3154. /* quirk for rs4xx HP dv5000 laptop to make it resume
  3155. * - it hangs on resume inside the dynclk 1 table.
  3156. */
  3157. if (rdev->family == CHIP_RS480 &&
  3158. rdev->pdev->subsystem_vendor == 0x103c &&
  3159. rdev->pdev->subsystem_device == 0x30a4)
  3160. return;
  3161. /* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
  3162. * - it hangs on resume inside the dynclk 1 table.
  3163. */
  3164. if (rdev->family == CHIP_RS480 &&
  3165. rdev->pdev->subsystem_vendor == 0x103c &&
  3166. rdev->pdev->subsystem_device == 0x30ae)
  3167. return;
  3168. /* quirk for rs4xx HP Compaq dc5750 Small Form Factor to make it resume
  3169. * - it hangs on resume inside the dynclk 1 table.
  3170. */
  3171. if (rdev->family == CHIP_RS480 &&
  3172. rdev->pdev->subsystem_vendor == 0x103c &&
  3173. rdev->pdev->subsystem_device == 0x280a)
  3174. return;
  3175. /* quirk for rs4xx Toshiba Sattellite L20-183 latop to make it resume
  3176. * - it hangs on resume inside the dynclk 1 table.
  3177. */
  3178. if (rdev->family == CHIP_RS400 &&
  3179. rdev->pdev->subsystem_vendor == 0x1179 &&
  3180. rdev->pdev->subsystem_device == 0xff31)
  3181. return;
  3182. /* DYN CLK 1 */
  3183. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  3184. if (table)
  3185. combios_parse_pll_table(dev, table);
  3186. }
  3187. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  3188. {
  3189. struct radeon_device *rdev = dev->dev_private;
  3190. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  3191. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3192. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3193. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  3194. /* let the bios control the backlight */
  3195. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  3196. /* tell the bios not to handle mode switching */
  3197. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  3198. RADEON_ACC_MODE_CHANGE);
  3199. /* tell the bios a driver is loaded */
  3200. bios_7_scratch |= RADEON_DRV_LOADED;
  3201. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3202. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3203. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  3204. }
  3205. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  3206. {
  3207. struct drm_device *dev = encoder->dev;
  3208. struct radeon_device *rdev = dev->dev_private;
  3209. uint32_t bios_6_scratch;
  3210. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3211. if (lock)
  3212. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  3213. else
  3214. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  3215. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3216. }
  3217. void
  3218. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  3219. struct drm_encoder *encoder,
  3220. bool connected)
  3221. {
  3222. struct drm_device *dev = connector->dev;
  3223. struct radeon_device *rdev = dev->dev_private;
  3224. struct radeon_connector *radeon_connector =
  3225. to_radeon_connector(connector);
  3226. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3227. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  3228. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3229. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3230. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3231. if (connected) {
  3232. DRM_DEBUG_KMS("TV1 connected\n");
  3233. /* fix me */
  3234. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  3235. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  3236. bios_5_scratch |= RADEON_TV1_ON;
  3237. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  3238. } else {
  3239. DRM_DEBUG_KMS("TV1 disconnected\n");
  3240. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  3241. bios_5_scratch &= ~RADEON_TV1_ON;
  3242. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  3243. }
  3244. }
  3245. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3246. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3247. if (connected) {
  3248. DRM_DEBUG_KMS("LCD1 connected\n");
  3249. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  3250. bios_5_scratch |= RADEON_LCD1_ON;
  3251. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  3252. } else {
  3253. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3254. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  3255. bios_5_scratch &= ~RADEON_LCD1_ON;
  3256. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  3257. }
  3258. }
  3259. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3260. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3261. if (connected) {
  3262. DRM_DEBUG_KMS("CRT1 connected\n");
  3263. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  3264. bios_5_scratch |= RADEON_CRT1_ON;
  3265. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  3266. } else {
  3267. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3268. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  3269. bios_5_scratch &= ~RADEON_CRT1_ON;
  3270. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  3271. }
  3272. }
  3273. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3274. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3275. if (connected) {
  3276. DRM_DEBUG_KMS("CRT2 connected\n");
  3277. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  3278. bios_5_scratch |= RADEON_CRT2_ON;
  3279. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  3280. } else {
  3281. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3282. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  3283. bios_5_scratch &= ~RADEON_CRT2_ON;
  3284. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  3285. }
  3286. }
  3287. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3288. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3289. if (connected) {
  3290. DRM_DEBUG_KMS("DFP1 connected\n");
  3291. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  3292. bios_5_scratch |= RADEON_DFP1_ON;
  3293. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  3294. } else {
  3295. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3296. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  3297. bios_5_scratch &= ~RADEON_DFP1_ON;
  3298. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  3299. }
  3300. }
  3301. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3302. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3303. if (connected) {
  3304. DRM_DEBUG_KMS("DFP2 connected\n");
  3305. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  3306. bios_5_scratch |= RADEON_DFP2_ON;
  3307. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  3308. } else {
  3309. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3310. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  3311. bios_5_scratch &= ~RADEON_DFP2_ON;
  3312. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  3313. }
  3314. }
  3315. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  3316. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3317. }
  3318. void
  3319. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3320. {
  3321. struct drm_device *dev = encoder->dev;
  3322. struct radeon_device *rdev = dev->dev_private;
  3323. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3324. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3325. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3326. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  3327. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  3328. }
  3329. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3330. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  3331. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  3332. }
  3333. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3334. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  3335. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  3336. }
  3337. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3338. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  3339. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  3340. }
  3341. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3342. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  3343. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  3344. }
  3345. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3346. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  3347. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  3348. }
  3349. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3350. }
  3351. void
  3352. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3353. {
  3354. struct drm_device *dev = encoder->dev;
  3355. struct radeon_device *rdev = dev->dev_private;
  3356. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3357. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3358. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  3359. if (on)
  3360. bios_6_scratch |= RADEON_TV_DPMS_ON;
  3361. else
  3362. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  3363. }
  3364. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3365. if (on)
  3366. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  3367. else
  3368. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  3369. }
  3370. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3371. if (on)
  3372. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  3373. else
  3374. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  3375. }
  3376. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  3377. if (on)
  3378. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  3379. else
  3380. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  3381. }
  3382. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3383. }