radeon_combios.c 91 KB

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