radeon_combios.c 93 KB

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