radeon_combios.c 96 KB

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