radeon_combios.c 90 KB

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