radeon_combios.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279
  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. unsigned char *raw;
  439. edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
  440. if (!edid_info)
  441. return false;
  442. raw = rdev->bios + edid_info;
  443. edid = kmalloc(EDID_LENGTH * (raw[0x7e] + 1), GFP_KERNEL);
  444. if (edid == NULL)
  445. return false;
  446. memcpy((unsigned char *)edid, raw, EDID_LENGTH * (raw[0x7e] + 1));
  447. if (!drm_edid_is_valid(edid)) {
  448. kfree(edid);
  449. return false;
  450. }
  451. rdev->mode_info.bios_hardcoded_edid = edid;
  452. return true;
  453. }
  454. struct edid *
  455. radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
  456. {
  457. if (rdev->mode_info.bios_hardcoded_edid)
  458. return rdev->mode_info.bios_hardcoded_edid;
  459. return NULL;
  460. }
  461. static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
  462. 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 = RADEON_HPD_NONE;
  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) == lvds->native_mode.vdisplay)) {
  1021. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1022. (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
  1023. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1024. (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
  1025. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1026. (RBIOS8(tmp + 23) * 8);
  1027. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1028. (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
  1029. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1030. ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
  1031. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1032. ((RBIOS16(tmp + 28) & 0xf800) >> 11);
  1033. lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
  1034. lvds->native_mode.flags = 0;
  1035. /* set crtc values */
  1036. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1037. }
  1038. }
  1039. } else {
  1040. DRM_INFO("No panel info found in BIOS\n");
  1041. lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
  1042. }
  1043. if (lvds)
  1044. encoder->native_mode = lvds->native_mode;
  1045. return lvds;
  1046. }
  1047. static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
  1048. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
  1049. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
  1050. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
  1051. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
  1052. {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
  1053. {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
  1054. {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
  1055. {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
  1056. {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
  1057. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
  1058. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
  1059. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
  1060. {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
  1061. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
  1062. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
  1063. {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
  1064. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
  1065. { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
  1066. };
  1067. bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
  1068. struct radeon_encoder_int_tmds *tmds)
  1069. {
  1070. struct drm_device *dev = encoder->base.dev;
  1071. struct radeon_device *rdev = dev->dev_private;
  1072. int i;
  1073. for (i = 0; i < 4; i++) {
  1074. tmds->tmds_pll[i].value =
  1075. default_tmds_pll[rdev->family][i].value;
  1076. tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
  1077. }
  1078. return true;
  1079. }
  1080. bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
  1081. struct radeon_encoder_int_tmds *tmds)
  1082. {
  1083. struct drm_device *dev = encoder->base.dev;
  1084. struct radeon_device *rdev = dev->dev_private;
  1085. uint16_t tmds_info;
  1086. int i, n;
  1087. uint8_t ver;
  1088. tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  1089. if (tmds_info) {
  1090. ver = RBIOS8(tmds_info);
  1091. DRM_INFO("DFP table revision: %d\n", ver);
  1092. if (ver == 3) {
  1093. n = RBIOS8(tmds_info + 5) + 1;
  1094. if (n > 4)
  1095. n = 4;
  1096. for (i = 0; i < n; i++) {
  1097. tmds->tmds_pll[i].value =
  1098. RBIOS32(tmds_info + i * 10 + 0x08);
  1099. tmds->tmds_pll[i].freq =
  1100. RBIOS16(tmds_info + i * 10 + 0x10);
  1101. DRM_DEBUG("TMDS PLL From COMBIOS %u %x\n",
  1102. tmds->tmds_pll[i].freq,
  1103. tmds->tmds_pll[i].value);
  1104. }
  1105. } else if (ver == 4) {
  1106. int stride = 0;
  1107. n = RBIOS8(tmds_info + 5) + 1;
  1108. if (n > 4)
  1109. n = 4;
  1110. for (i = 0; i < n; i++) {
  1111. tmds->tmds_pll[i].value =
  1112. RBIOS32(tmds_info + stride + 0x08);
  1113. tmds->tmds_pll[i].freq =
  1114. RBIOS16(tmds_info + stride + 0x10);
  1115. if (i == 0)
  1116. stride += 10;
  1117. else
  1118. stride += 6;
  1119. DRM_DEBUG("TMDS PLL From COMBIOS %u %x\n",
  1120. tmds->tmds_pll[i].freq,
  1121. tmds->tmds_pll[i].value);
  1122. }
  1123. }
  1124. } else {
  1125. DRM_INFO("No TMDS info found in BIOS\n");
  1126. return false;
  1127. }
  1128. return true;
  1129. }
  1130. bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
  1131. struct radeon_encoder_ext_tmds *tmds)
  1132. {
  1133. struct drm_device *dev = encoder->base.dev;
  1134. struct radeon_device *rdev = dev->dev_private;
  1135. struct radeon_i2c_bus_rec i2c_bus;
  1136. /* default for macs */
  1137. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1138. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1139. /* XXX some macs have duallink chips */
  1140. switch (rdev->mode_info.connector_table) {
  1141. case CT_POWERBOOK_EXTERNAL:
  1142. case CT_MINI_EXTERNAL:
  1143. default:
  1144. tmds->dvo_chip = DVO_SIL164;
  1145. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1146. break;
  1147. }
  1148. return true;
  1149. }
  1150. bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
  1151. struct radeon_encoder_ext_tmds *tmds)
  1152. {
  1153. struct drm_device *dev = encoder->base.dev;
  1154. struct radeon_device *rdev = dev->dev_private;
  1155. uint16_t offset;
  1156. uint8_t ver, id, blocks, clk, data;
  1157. int i;
  1158. enum radeon_combios_ddc gpio;
  1159. struct radeon_i2c_bus_rec i2c_bus;
  1160. tmds->i2c_bus = NULL;
  1161. if (rdev->flags & RADEON_IS_IGP) {
  1162. offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
  1163. if (offset) {
  1164. ver = RBIOS8(offset);
  1165. DRM_INFO("GPIO Table revision: %d\n", ver);
  1166. blocks = RBIOS8(offset + 2);
  1167. for (i = 0; i < blocks; i++) {
  1168. id = RBIOS8(offset + 3 + (i * 5) + 0);
  1169. if (id == 136) {
  1170. clk = RBIOS8(offset + 3 + (i * 5) + 3);
  1171. data = RBIOS8(offset + 3 + (i * 5) + 4);
  1172. i2c_bus.valid = true;
  1173. i2c_bus.mask_clk_mask = (1 << clk);
  1174. i2c_bus.mask_data_mask = (1 << data);
  1175. i2c_bus.a_clk_mask = (1 << clk);
  1176. i2c_bus.a_data_mask = (1 << data);
  1177. i2c_bus.en_clk_mask = (1 << clk);
  1178. i2c_bus.en_data_mask = (1 << data);
  1179. i2c_bus.y_clk_mask = (1 << clk);
  1180. i2c_bus.y_data_mask = (1 << data);
  1181. i2c_bus.mask_clk_reg = RADEON_GPIOPAD_MASK;
  1182. i2c_bus.mask_data_reg = RADEON_GPIOPAD_MASK;
  1183. i2c_bus.a_clk_reg = RADEON_GPIOPAD_A;
  1184. i2c_bus.a_data_reg = RADEON_GPIOPAD_A;
  1185. i2c_bus.en_clk_reg = RADEON_GPIOPAD_EN;
  1186. i2c_bus.en_data_reg = RADEON_GPIOPAD_EN;
  1187. i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y;
  1188. i2c_bus.y_data_reg = RADEON_GPIOPAD_Y;
  1189. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1190. tmds->dvo_chip = DVO_SIL164;
  1191. tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
  1192. break;
  1193. }
  1194. }
  1195. }
  1196. } else {
  1197. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  1198. if (offset) {
  1199. ver = RBIOS8(offset);
  1200. DRM_INFO("External TMDS Table revision: %d\n", ver);
  1201. tmds->slave_addr = RBIOS8(offset + 4 + 2);
  1202. tmds->slave_addr >>= 1; /* 7 bit addressing */
  1203. gpio = RBIOS8(offset + 4 + 3);
  1204. switch (gpio) {
  1205. case DDC_MONID:
  1206. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1207. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1208. break;
  1209. case DDC_DVI:
  1210. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1211. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1212. break;
  1213. case DDC_VGA:
  1214. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1215. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1216. break;
  1217. case DDC_CRT2:
  1218. /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
  1219. if (rdev->family >= CHIP_R300)
  1220. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1221. else
  1222. i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1223. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1224. break;
  1225. case DDC_LCD: /* MM i2c */
  1226. i2c_bus.valid = true;
  1227. i2c_bus.hw_capable = true;
  1228. i2c_bus.mm_i2c = true;
  1229. tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
  1230. break;
  1231. default:
  1232. DRM_ERROR("Unsupported gpio %d\n", gpio);
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. if (!tmds->i2c_bus) {
  1238. DRM_INFO("No valid Ext TMDS info found in BIOS\n");
  1239. return false;
  1240. }
  1241. return true;
  1242. }
  1243. bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
  1244. {
  1245. struct radeon_device *rdev = dev->dev_private;
  1246. struct radeon_i2c_bus_rec ddc_i2c;
  1247. struct radeon_hpd hpd;
  1248. rdev->mode_info.connector_table = radeon_connector_table;
  1249. if (rdev->mode_info.connector_table == CT_NONE) {
  1250. #ifdef CONFIG_PPC_PMAC
  1251. if (of_machine_is_compatible("PowerBook3,3")) {
  1252. /* powerbook with VGA */
  1253. rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
  1254. } else if (of_machine_is_compatible("PowerBook3,4") ||
  1255. of_machine_is_compatible("PowerBook3,5")) {
  1256. /* powerbook with internal tmds */
  1257. rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
  1258. } else if (of_machine_is_compatible("PowerBook5,1") ||
  1259. of_machine_is_compatible("PowerBook5,2") ||
  1260. of_machine_is_compatible("PowerBook5,3") ||
  1261. of_machine_is_compatible("PowerBook5,4") ||
  1262. of_machine_is_compatible("PowerBook5,5")) {
  1263. /* powerbook with external single link tmds (sil164) */
  1264. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1265. } else if (of_machine_is_compatible("PowerBook5,6")) {
  1266. /* powerbook with external dual or single link tmds */
  1267. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1268. } else if (of_machine_is_compatible("PowerBook5,7") ||
  1269. of_machine_is_compatible("PowerBook5,8") ||
  1270. of_machine_is_compatible("PowerBook5,9")) {
  1271. /* PowerBook6,2 ? */
  1272. /* powerbook with external dual link tmds (sil1178?) */
  1273. rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
  1274. } else if (of_machine_is_compatible("PowerBook4,1") ||
  1275. of_machine_is_compatible("PowerBook4,2") ||
  1276. of_machine_is_compatible("PowerBook4,3") ||
  1277. of_machine_is_compatible("PowerBook6,3") ||
  1278. of_machine_is_compatible("PowerBook6,5") ||
  1279. of_machine_is_compatible("PowerBook6,7")) {
  1280. /* ibook */
  1281. rdev->mode_info.connector_table = CT_IBOOK;
  1282. } else if (of_machine_is_compatible("PowerMac4,4")) {
  1283. /* emac */
  1284. rdev->mode_info.connector_table = CT_EMAC;
  1285. } else if (of_machine_is_compatible("PowerMac10,1")) {
  1286. /* mini with internal tmds */
  1287. rdev->mode_info.connector_table = CT_MINI_INTERNAL;
  1288. } else if (of_machine_is_compatible("PowerMac10,2")) {
  1289. /* mini with external tmds */
  1290. rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
  1291. } else if (of_machine_is_compatible("PowerMac12,1")) {
  1292. /* PowerMac8,1 ? */
  1293. /* imac g5 isight */
  1294. rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
  1295. } else
  1296. #endif /* CONFIG_PPC_PMAC */
  1297. #ifdef CONFIG_PPC64
  1298. if (ASIC_IS_RN50(rdev))
  1299. rdev->mode_info.connector_table = CT_RN50_POWER;
  1300. else
  1301. #endif
  1302. rdev->mode_info.connector_table = CT_GENERIC;
  1303. }
  1304. switch (rdev->mode_info.connector_table) {
  1305. case CT_GENERIC:
  1306. DRM_INFO("Connector Table: %d (generic)\n",
  1307. rdev->mode_info.connector_table);
  1308. /* these are the most common settings */
  1309. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1310. /* VGA - primary dac */
  1311. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1312. hpd.hpd = RADEON_HPD_NONE;
  1313. radeon_add_legacy_encoder(dev,
  1314. radeon_get_encoder_id(dev,
  1315. ATOM_DEVICE_CRT1_SUPPORT,
  1316. 1),
  1317. ATOM_DEVICE_CRT1_SUPPORT);
  1318. radeon_add_legacy_connector(dev, 0,
  1319. ATOM_DEVICE_CRT1_SUPPORT,
  1320. DRM_MODE_CONNECTOR_VGA,
  1321. &ddc_i2c,
  1322. CONNECTOR_OBJECT_ID_VGA,
  1323. &hpd);
  1324. } else if (rdev->flags & RADEON_IS_MOBILITY) {
  1325. /* LVDS */
  1326. ddc_i2c = combios_setup_i2c_bus(rdev, 0);
  1327. hpd.hpd = RADEON_HPD_NONE;
  1328. radeon_add_legacy_encoder(dev,
  1329. radeon_get_encoder_id(dev,
  1330. ATOM_DEVICE_LCD1_SUPPORT,
  1331. 0),
  1332. ATOM_DEVICE_LCD1_SUPPORT);
  1333. radeon_add_legacy_connector(dev, 0,
  1334. ATOM_DEVICE_LCD1_SUPPORT,
  1335. DRM_MODE_CONNECTOR_LVDS,
  1336. &ddc_i2c,
  1337. CONNECTOR_OBJECT_ID_LVDS,
  1338. &hpd);
  1339. /* VGA - primary dac */
  1340. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1341. hpd.hpd = RADEON_HPD_NONE;
  1342. radeon_add_legacy_encoder(dev,
  1343. radeon_get_encoder_id(dev,
  1344. ATOM_DEVICE_CRT1_SUPPORT,
  1345. 1),
  1346. ATOM_DEVICE_CRT1_SUPPORT);
  1347. radeon_add_legacy_connector(dev, 1,
  1348. ATOM_DEVICE_CRT1_SUPPORT,
  1349. DRM_MODE_CONNECTOR_VGA,
  1350. &ddc_i2c,
  1351. CONNECTOR_OBJECT_ID_VGA,
  1352. &hpd);
  1353. } else {
  1354. /* DVI-I - tv dac, int tmds */
  1355. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1356. hpd.hpd = RADEON_HPD_1;
  1357. radeon_add_legacy_encoder(dev,
  1358. radeon_get_encoder_id(dev,
  1359. ATOM_DEVICE_DFP1_SUPPORT,
  1360. 0),
  1361. ATOM_DEVICE_DFP1_SUPPORT);
  1362. radeon_add_legacy_encoder(dev,
  1363. radeon_get_encoder_id(dev,
  1364. ATOM_DEVICE_CRT2_SUPPORT,
  1365. 2),
  1366. ATOM_DEVICE_CRT2_SUPPORT);
  1367. radeon_add_legacy_connector(dev, 0,
  1368. ATOM_DEVICE_DFP1_SUPPORT |
  1369. ATOM_DEVICE_CRT2_SUPPORT,
  1370. DRM_MODE_CONNECTOR_DVII,
  1371. &ddc_i2c,
  1372. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1373. &hpd);
  1374. /* VGA - primary dac */
  1375. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1376. hpd.hpd = RADEON_HPD_NONE;
  1377. radeon_add_legacy_encoder(dev,
  1378. radeon_get_encoder_id(dev,
  1379. ATOM_DEVICE_CRT1_SUPPORT,
  1380. 1),
  1381. ATOM_DEVICE_CRT1_SUPPORT);
  1382. radeon_add_legacy_connector(dev, 1,
  1383. ATOM_DEVICE_CRT1_SUPPORT,
  1384. DRM_MODE_CONNECTOR_VGA,
  1385. &ddc_i2c,
  1386. CONNECTOR_OBJECT_ID_VGA,
  1387. &hpd);
  1388. }
  1389. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  1390. /* TV - tv dac */
  1391. ddc_i2c.valid = false;
  1392. hpd.hpd = RADEON_HPD_NONE;
  1393. radeon_add_legacy_encoder(dev,
  1394. radeon_get_encoder_id(dev,
  1395. ATOM_DEVICE_TV1_SUPPORT,
  1396. 2),
  1397. ATOM_DEVICE_TV1_SUPPORT);
  1398. radeon_add_legacy_connector(dev, 2,
  1399. ATOM_DEVICE_TV1_SUPPORT,
  1400. DRM_MODE_CONNECTOR_SVIDEO,
  1401. &ddc_i2c,
  1402. CONNECTOR_OBJECT_ID_SVIDEO,
  1403. &hpd);
  1404. }
  1405. break;
  1406. case CT_IBOOK:
  1407. DRM_INFO("Connector Table: %d (ibook)\n",
  1408. rdev->mode_info.connector_table);
  1409. /* LVDS */
  1410. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1411. hpd.hpd = RADEON_HPD_NONE;
  1412. radeon_add_legacy_encoder(dev,
  1413. radeon_get_encoder_id(dev,
  1414. ATOM_DEVICE_LCD1_SUPPORT,
  1415. 0),
  1416. ATOM_DEVICE_LCD1_SUPPORT);
  1417. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1418. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1419. CONNECTOR_OBJECT_ID_LVDS,
  1420. &hpd);
  1421. /* VGA - TV DAC */
  1422. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1423. hpd.hpd = RADEON_HPD_NONE;
  1424. radeon_add_legacy_encoder(dev,
  1425. radeon_get_encoder_id(dev,
  1426. ATOM_DEVICE_CRT2_SUPPORT,
  1427. 2),
  1428. ATOM_DEVICE_CRT2_SUPPORT);
  1429. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1430. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1431. CONNECTOR_OBJECT_ID_VGA,
  1432. &hpd);
  1433. /* TV - TV DAC */
  1434. ddc_i2c.valid = false;
  1435. hpd.hpd = RADEON_HPD_NONE;
  1436. radeon_add_legacy_encoder(dev,
  1437. radeon_get_encoder_id(dev,
  1438. ATOM_DEVICE_TV1_SUPPORT,
  1439. 2),
  1440. ATOM_DEVICE_TV1_SUPPORT);
  1441. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1442. DRM_MODE_CONNECTOR_SVIDEO,
  1443. &ddc_i2c,
  1444. CONNECTOR_OBJECT_ID_SVIDEO,
  1445. &hpd);
  1446. break;
  1447. case CT_POWERBOOK_EXTERNAL:
  1448. DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
  1449. rdev->mode_info.connector_table);
  1450. /* LVDS */
  1451. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1452. hpd.hpd = RADEON_HPD_NONE;
  1453. radeon_add_legacy_encoder(dev,
  1454. radeon_get_encoder_id(dev,
  1455. ATOM_DEVICE_LCD1_SUPPORT,
  1456. 0),
  1457. ATOM_DEVICE_LCD1_SUPPORT);
  1458. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1459. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1460. CONNECTOR_OBJECT_ID_LVDS,
  1461. &hpd);
  1462. /* DVI-I - primary dac, ext tmds */
  1463. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1464. hpd.hpd = RADEON_HPD_2; /* ??? */
  1465. radeon_add_legacy_encoder(dev,
  1466. radeon_get_encoder_id(dev,
  1467. ATOM_DEVICE_DFP2_SUPPORT,
  1468. 0),
  1469. ATOM_DEVICE_DFP2_SUPPORT);
  1470. radeon_add_legacy_encoder(dev,
  1471. radeon_get_encoder_id(dev,
  1472. ATOM_DEVICE_CRT1_SUPPORT,
  1473. 1),
  1474. ATOM_DEVICE_CRT1_SUPPORT);
  1475. /* XXX some are SL */
  1476. radeon_add_legacy_connector(dev, 1,
  1477. ATOM_DEVICE_DFP2_SUPPORT |
  1478. ATOM_DEVICE_CRT1_SUPPORT,
  1479. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1480. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
  1481. &hpd);
  1482. /* TV - TV DAC */
  1483. ddc_i2c.valid = false;
  1484. hpd.hpd = RADEON_HPD_NONE;
  1485. radeon_add_legacy_encoder(dev,
  1486. radeon_get_encoder_id(dev,
  1487. ATOM_DEVICE_TV1_SUPPORT,
  1488. 2),
  1489. ATOM_DEVICE_TV1_SUPPORT);
  1490. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1491. DRM_MODE_CONNECTOR_SVIDEO,
  1492. &ddc_i2c,
  1493. CONNECTOR_OBJECT_ID_SVIDEO,
  1494. &hpd);
  1495. break;
  1496. case CT_POWERBOOK_INTERNAL:
  1497. DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
  1498. rdev->mode_info.connector_table);
  1499. /* LVDS */
  1500. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1501. hpd.hpd = RADEON_HPD_NONE;
  1502. radeon_add_legacy_encoder(dev,
  1503. radeon_get_encoder_id(dev,
  1504. ATOM_DEVICE_LCD1_SUPPORT,
  1505. 0),
  1506. ATOM_DEVICE_LCD1_SUPPORT);
  1507. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1508. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1509. CONNECTOR_OBJECT_ID_LVDS,
  1510. &hpd);
  1511. /* DVI-I - primary dac, int tmds */
  1512. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1513. hpd.hpd = RADEON_HPD_1; /* ??? */
  1514. radeon_add_legacy_encoder(dev,
  1515. radeon_get_encoder_id(dev,
  1516. ATOM_DEVICE_DFP1_SUPPORT,
  1517. 0),
  1518. ATOM_DEVICE_DFP1_SUPPORT);
  1519. radeon_add_legacy_encoder(dev,
  1520. radeon_get_encoder_id(dev,
  1521. ATOM_DEVICE_CRT1_SUPPORT,
  1522. 1),
  1523. ATOM_DEVICE_CRT1_SUPPORT);
  1524. radeon_add_legacy_connector(dev, 1,
  1525. ATOM_DEVICE_DFP1_SUPPORT |
  1526. ATOM_DEVICE_CRT1_SUPPORT,
  1527. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1528. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1529. &hpd);
  1530. /* TV - TV DAC */
  1531. ddc_i2c.valid = false;
  1532. hpd.hpd = RADEON_HPD_NONE;
  1533. radeon_add_legacy_encoder(dev,
  1534. radeon_get_encoder_id(dev,
  1535. ATOM_DEVICE_TV1_SUPPORT,
  1536. 2),
  1537. ATOM_DEVICE_TV1_SUPPORT);
  1538. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1539. DRM_MODE_CONNECTOR_SVIDEO,
  1540. &ddc_i2c,
  1541. CONNECTOR_OBJECT_ID_SVIDEO,
  1542. &hpd);
  1543. break;
  1544. case CT_POWERBOOK_VGA:
  1545. DRM_INFO("Connector Table: %d (powerbook vga)\n",
  1546. rdev->mode_info.connector_table);
  1547. /* LVDS */
  1548. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1549. hpd.hpd = RADEON_HPD_NONE;
  1550. radeon_add_legacy_encoder(dev,
  1551. radeon_get_encoder_id(dev,
  1552. ATOM_DEVICE_LCD1_SUPPORT,
  1553. 0),
  1554. ATOM_DEVICE_LCD1_SUPPORT);
  1555. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
  1556. DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
  1557. CONNECTOR_OBJECT_ID_LVDS,
  1558. &hpd);
  1559. /* VGA - primary dac */
  1560. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1561. hpd.hpd = RADEON_HPD_NONE;
  1562. radeon_add_legacy_encoder(dev,
  1563. radeon_get_encoder_id(dev,
  1564. ATOM_DEVICE_CRT1_SUPPORT,
  1565. 1),
  1566. ATOM_DEVICE_CRT1_SUPPORT);
  1567. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
  1568. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1569. CONNECTOR_OBJECT_ID_VGA,
  1570. &hpd);
  1571. /* TV - TV DAC */
  1572. ddc_i2c.valid = false;
  1573. hpd.hpd = RADEON_HPD_NONE;
  1574. radeon_add_legacy_encoder(dev,
  1575. radeon_get_encoder_id(dev,
  1576. ATOM_DEVICE_TV1_SUPPORT,
  1577. 2),
  1578. ATOM_DEVICE_TV1_SUPPORT);
  1579. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1580. DRM_MODE_CONNECTOR_SVIDEO,
  1581. &ddc_i2c,
  1582. CONNECTOR_OBJECT_ID_SVIDEO,
  1583. &hpd);
  1584. break;
  1585. case CT_MINI_EXTERNAL:
  1586. DRM_INFO("Connector Table: %d (mini external tmds)\n",
  1587. rdev->mode_info.connector_table);
  1588. /* DVI-I - tv dac, ext tmds */
  1589. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1590. hpd.hpd = RADEON_HPD_2; /* ??? */
  1591. radeon_add_legacy_encoder(dev,
  1592. radeon_get_encoder_id(dev,
  1593. ATOM_DEVICE_DFP2_SUPPORT,
  1594. 0),
  1595. ATOM_DEVICE_DFP2_SUPPORT);
  1596. radeon_add_legacy_encoder(dev,
  1597. radeon_get_encoder_id(dev,
  1598. ATOM_DEVICE_CRT2_SUPPORT,
  1599. 2),
  1600. ATOM_DEVICE_CRT2_SUPPORT);
  1601. /* XXX are any DL? */
  1602. radeon_add_legacy_connector(dev, 0,
  1603. ATOM_DEVICE_DFP2_SUPPORT |
  1604. ATOM_DEVICE_CRT2_SUPPORT,
  1605. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1606. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1607. &hpd);
  1608. /* TV - TV DAC */
  1609. ddc_i2c.valid = false;
  1610. hpd.hpd = RADEON_HPD_NONE;
  1611. radeon_add_legacy_encoder(dev,
  1612. radeon_get_encoder_id(dev,
  1613. ATOM_DEVICE_TV1_SUPPORT,
  1614. 2),
  1615. ATOM_DEVICE_TV1_SUPPORT);
  1616. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1617. DRM_MODE_CONNECTOR_SVIDEO,
  1618. &ddc_i2c,
  1619. CONNECTOR_OBJECT_ID_SVIDEO,
  1620. &hpd);
  1621. break;
  1622. case CT_MINI_INTERNAL:
  1623. DRM_INFO("Connector Table: %d (mini internal tmds)\n",
  1624. rdev->mode_info.connector_table);
  1625. /* DVI-I - tv dac, int tmds */
  1626. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1627. hpd.hpd = RADEON_HPD_1; /* ??? */
  1628. radeon_add_legacy_encoder(dev,
  1629. radeon_get_encoder_id(dev,
  1630. ATOM_DEVICE_DFP1_SUPPORT,
  1631. 0),
  1632. ATOM_DEVICE_DFP1_SUPPORT);
  1633. radeon_add_legacy_encoder(dev,
  1634. radeon_get_encoder_id(dev,
  1635. ATOM_DEVICE_CRT2_SUPPORT,
  1636. 2),
  1637. ATOM_DEVICE_CRT2_SUPPORT);
  1638. radeon_add_legacy_connector(dev, 0,
  1639. ATOM_DEVICE_DFP1_SUPPORT |
  1640. ATOM_DEVICE_CRT2_SUPPORT,
  1641. DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
  1642. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  1643. &hpd);
  1644. /* TV - TV DAC */
  1645. ddc_i2c.valid = false;
  1646. hpd.hpd = RADEON_HPD_NONE;
  1647. radeon_add_legacy_encoder(dev,
  1648. radeon_get_encoder_id(dev,
  1649. ATOM_DEVICE_TV1_SUPPORT,
  1650. 2),
  1651. ATOM_DEVICE_TV1_SUPPORT);
  1652. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
  1653. DRM_MODE_CONNECTOR_SVIDEO,
  1654. &ddc_i2c,
  1655. CONNECTOR_OBJECT_ID_SVIDEO,
  1656. &hpd);
  1657. break;
  1658. case CT_IMAC_G5_ISIGHT:
  1659. DRM_INFO("Connector Table: %d (imac g5 isight)\n",
  1660. rdev->mode_info.connector_table);
  1661. /* DVI-D - int tmds */
  1662. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1663. hpd.hpd = RADEON_HPD_1; /* ??? */
  1664. radeon_add_legacy_encoder(dev,
  1665. radeon_get_encoder_id(dev,
  1666. ATOM_DEVICE_DFP1_SUPPORT,
  1667. 0),
  1668. ATOM_DEVICE_DFP1_SUPPORT);
  1669. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
  1670. DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
  1671. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  1672. &hpd);
  1673. /* VGA - tv dac */
  1674. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1675. hpd.hpd = RADEON_HPD_NONE;
  1676. radeon_add_legacy_encoder(dev,
  1677. radeon_get_encoder_id(dev,
  1678. ATOM_DEVICE_CRT2_SUPPORT,
  1679. 2),
  1680. ATOM_DEVICE_CRT2_SUPPORT);
  1681. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1682. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1683. CONNECTOR_OBJECT_ID_VGA,
  1684. &hpd);
  1685. /* TV - TV DAC */
  1686. ddc_i2c.valid = false;
  1687. hpd.hpd = RADEON_HPD_NONE;
  1688. radeon_add_legacy_encoder(dev,
  1689. radeon_get_encoder_id(dev,
  1690. ATOM_DEVICE_TV1_SUPPORT,
  1691. 2),
  1692. ATOM_DEVICE_TV1_SUPPORT);
  1693. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1694. DRM_MODE_CONNECTOR_SVIDEO,
  1695. &ddc_i2c,
  1696. CONNECTOR_OBJECT_ID_SVIDEO,
  1697. &hpd);
  1698. break;
  1699. case CT_EMAC:
  1700. DRM_INFO("Connector Table: %d (emac)\n",
  1701. rdev->mode_info.connector_table);
  1702. /* VGA - primary dac */
  1703. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1704. hpd.hpd = RADEON_HPD_NONE;
  1705. radeon_add_legacy_encoder(dev,
  1706. radeon_get_encoder_id(dev,
  1707. ATOM_DEVICE_CRT1_SUPPORT,
  1708. 1),
  1709. ATOM_DEVICE_CRT1_SUPPORT);
  1710. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1711. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1712. CONNECTOR_OBJECT_ID_VGA,
  1713. &hpd);
  1714. /* VGA - tv dac */
  1715. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1716. hpd.hpd = RADEON_HPD_NONE;
  1717. radeon_add_legacy_encoder(dev,
  1718. radeon_get_encoder_id(dev,
  1719. ATOM_DEVICE_CRT2_SUPPORT,
  1720. 2),
  1721. ATOM_DEVICE_CRT2_SUPPORT);
  1722. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1723. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1724. CONNECTOR_OBJECT_ID_VGA,
  1725. &hpd);
  1726. /* TV - TV DAC */
  1727. ddc_i2c.valid = false;
  1728. hpd.hpd = RADEON_HPD_NONE;
  1729. radeon_add_legacy_encoder(dev,
  1730. radeon_get_encoder_id(dev,
  1731. ATOM_DEVICE_TV1_SUPPORT,
  1732. 2),
  1733. ATOM_DEVICE_TV1_SUPPORT);
  1734. radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
  1735. DRM_MODE_CONNECTOR_SVIDEO,
  1736. &ddc_i2c,
  1737. CONNECTOR_OBJECT_ID_SVIDEO,
  1738. &hpd);
  1739. break;
  1740. case CT_RN50_POWER:
  1741. DRM_INFO("Connector Table: %d (rn50-power)\n",
  1742. rdev->mode_info.connector_table);
  1743. /* VGA - primary dac */
  1744. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1745. hpd.hpd = RADEON_HPD_NONE;
  1746. radeon_add_legacy_encoder(dev,
  1747. radeon_get_encoder_id(dev,
  1748. ATOM_DEVICE_CRT1_SUPPORT,
  1749. 1),
  1750. ATOM_DEVICE_CRT1_SUPPORT);
  1751. radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
  1752. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1753. CONNECTOR_OBJECT_ID_VGA,
  1754. &hpd);
  1755. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1756. hpd.hpd = RADEON_HPD_NONE;
  1757. radeon_add_legacy_encoder(dev,
  1758. radeon_get_encoder_id(dev,
  1759. ATOM_DEVICE_CRT2_SUPPORT,
  1760. 2),
  1761. ATOM_DEVICE_CRT2_SUPPORT);
  1762. radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
  1763. DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
  1764. CONNECTOR_OBJECT_ID_VGA,
  1765. &hpd);
  1766. break;
  1767. default:
  1768. DRM_INFO("Connector table: %d (invalid)\n",
  1769. rdev->mode_info.connector_table);
  1770. return false;
  1771. }
  1772. radeon_link_encoder_connector(dev);
  1773. return true;
  1774. }
  1775. static bool radeon_apply_legacy_quirks(struct drm_device *dev,
  1776. int bios_index,
  1777. enum radeon_combios_connector
  1778. *legacy_connector,
  1779. struct radeon_i2c_bus_rec *ddc_i2c,
  1780. struct radeon_hpd *hpd)
  1781. {
  1782. struct radeon_device *rdev = dev->dev_private;
  1783. /* XPRESS DDC quirks */
  1784. if ((rdev->family == CHIP_RS400 ||
  1785. rdev->family == CHIP_RS480) &&
  1786. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  1787. *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1788. else if ((rdev->family == CHIP_RS400 ||
  1789. rdev->family == CHIP_RS480) &&
  1790. ddc_i2c->mask_clk_reg == RADEON_GPIO_MONID) {
  1791. *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIOPAD_MASK);
  1792. ddc_i2c->mask_clk_mask = (0x20 << 8);
  1793. ddc_i2c->mask_data_mask = 0x80;
  1794. ddc_i2c->a_clk_mask = (0x20 << 8);
  1795. ddc_i2c->a_data_mask = 0x80;
  1796. ddc_i2c->en_clk_mask = (0x20 << 8);
  1797. ddc_i2c->en_data_mask = 0x80;
  1798. ddc_i2c->y_clk_mask = (0x20 << 8);
  1799. ddc_i2c->y_data_mask = 0x80;
  1800. }
  1801. /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
  1802. if ((rdev->family >= CHIP_R300) &&
  1803. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  1804. *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1805. /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
  1806. one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
  1807. if (dev->pdev->device == 0x515e &&
  1808. dev->pdev->subsystem_vendor == 0x1014) {
  1809. if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
  1810. ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
  1811. return false;
  1812. }
  1813. /* X300 card with extra non-existent DVI port */
  1814. if (dev->pdev->device == 0x5B60 &&
  1815. dev->pdev->subsystem_vendor == 0x17af &&
  1816. dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
  1817. if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
  1818. return false;
  1819. }
  1820. return true;
  1821. }
  1822. static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
  1823. {
  1824. /* Acer 5102 has non-existent TV port */
  1825. if (dev->pdev->device == 0x5975 &&
  1826. dev->pdev->subsystem_vendor == 0x1025 &&
  1827. dev->pdev->subsystem_device == 0x009f)
  1828. return false;
  1829. /* HP dc5750 has non-existent TV port */
  1830. if (dev->pdev->device == 0x5974 &&
  1831. dev->pdev->subsystem_vendor == 0x103c &&
  1832. dev->pdev->subsystem_device == 0x280a)
  1833. return false;
  1834. /* MSI S270 has non-existent TV port */
  1835. if (dev->pdev->device == 0x5955 &&
  1836. dev->pdev->subsystem_vendor == 0x1462 &&
  1837. dev->pdev->subsystem_device == 0x0131)
  1838. return false;
  1839. return true;
  1840. }
  1841. static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
  1842. {
  1843. struct radeon_device *rdev = dev->dev_private;
  1844. uint32_t ext_tmds_info;
  1845. if (rdev->flags & RADEON_IS_IGP) {
  1846. if (is_dvi_d)
  1847. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  1848. else
  1849. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  1850. }
  1851. ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  1852. if (ext_tmds_info) {
  1853. uint8_t rev = RBIOS8(ext_tmds_info);
  1854. uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
  1855. if (rev >= 3) {
  1856. if (is_dvi_d)
  1857. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  1858. else
  1859. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  1860. } else {
  1861. if (flags & 1) {
  1862. if (is_dvi_d)
  1863. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  1864. else
  1865. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  1866. }
  1867. }
  1868. }
  1869. if (is_dvi_d)
  1870. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  1871. else
  1872. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  1873. }
  1874. bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
  1875. {
  1876. struct radeon_device *rdev = dev->dev_private;
  1877. uint32_t conn_info, entry, devices;
  1878. uint16_t tmp, connector_object_id;
  1879. enum radeon_combios_ddc ddc_type;
  1880. enum radeon_combios_connector connector;
  1881. int i = 0;
  1882. struct radeon_i2c_bus_rec ddc_i2c;
  1883. struct radeon_hpd hpd;
  1884. conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
  1885. if (conn_info) {
  1886. for (i = 0; i < 4; i++) {
  1887. entry = conn_info + 2 + i * 2;
  1888. if (!RBIOS16(entry))
  1889. break;
  1890. tmp = RBIOS16(entry);
  1891. connector = (tmp >> 12) & 0xf;
  1892. ddc_type = (tmp >> 8) & 0xf;
  1893. switch (ddc_type) {
  1894. case DDC_MONID:
  1895. ddc_i2c =
  1896. combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
  1897. break;
  1898. case DDC_DVI:
  1899. ddc_i2c =
  1900. combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  1901. break;
  1902. case DDC_VGA:
  1903. ddc_i2c =
  1904. combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  1905. break;
  1906. case DDC_CRT2:
  1907. ddc_i2c =
  1908. combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
  1909. break;
  1910. default:
  1911. ddc_i2c.valid = false;
  1912. break;
  1913. }
  1914. switch (connector) {
  1915. case CONNECTOR_PROPRIETARY_LEGACY:
  1916. case CONNECTOR_DVI_I_LEGACY:
  1917. case CONNECTOR_DVI_D_LEGACY:
  1918. if ((tmp >> 4) & 0x1)
  1919. hpd.hpd = RADEON_HPD_2;
  1920. else
  1921. hpd.hpd = RADEON_HPD_1;
  1922. break;
  1923. default:
  1924. hpd.hpd = RADEON_HPD_NONE;
  1925. break;
  1926. }
  1927. if (!radeon_apply_legacy_quirks(dev, i, &connector,
  1928. &ddc_i2c, &hpd))
  1929. continue;
  1930. switch (connector) {
  1931. case CONNECTOR_PROPRIETARY_LEGACY:
  1932. if ((tmp >> 4) & 0x1)
  1933. devices = ATOM_DEVICE_DFP2_SUPPORT;
  1934. else
  1935. devices = ATOM_DEVICE_DFP1_SUPPORT;
  1936. radeon_add_legacy_encoder(dev,
  1937. radeon_get_encoder_id
  1938. (dev, devices, 0),
  1939. devices);
  1940. radeon_add_legacy_connector(dev, i, devices,
  1941. legacy_connector_convert
  1942. [connector],
  1943. &ddc_i2c,
  1944. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
  1945. &hpd);
  1946. break;
  1947. case CONNECTOR_CRT_LEGACY:
  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. radeon_add_legacy_connector(dev,
  1966. i,
  1967. devices,
  1968. legacy_connector_convert
  1969. [connector],
  1970. &ddc_i2c,
  1971. CONNECTOR_OBJECT_ID_VGA,
  1972. &hpd);
  1973. break;
  1974. case CONNECTOR_DVI_I_LEGACY:
  1975. devices = 0;
  1976. if (tmp & 0x1) {
  1977. devices |= ATOM_DEVICE_CRT2_SUPPORT;
  1978. radeon_add_legacy_encoder(dev,
  1979. radeon_get_encoder_id
  1980. (dev,
  1981. ATOM_DEVICE_CRT2_SUPPORT,
  1982. 2),
  1983. ATOM_DEVICE_CRT2_SUPPORT);
  1984. } else {
  1985. devices |= ATOM_DEVICE_CRT1_SUPPORT;
  1986. radeon_add_legacy_encoder(dev,
  1987. radeon_get_encoder_id
  1988. (dev,
  1989. ATOM_DEVICE_CRT1_SUPPORT,
  1990. 1),
  1991. ATOM_DEVICE_CRT1_SUPPORT);
  1992. }
  1993. if ((tmp >> 4) & 0x1) {
  1994. devices |= ATOM_DEVICE_DFP2_SUPPORT;
  1995. radeon_add_legacy_encoder(dev,
  1996. radeon_get_encoder_id
  1997. (dev,
  1998. ATOM_DEVICE_DFP2_SUPPORT,
  1999. 0),
  2000. ATOM_DEVICE_DFP2_SUPPORT);
  2001. connector_object_id = combios_check_dl_dvi(dev, 0);
  2002. } else {
  2003. devices |= ATOM_DEVICE_DFP1_SUPPORT;
  2004. radeon_add_legacy_encoder(dev,
  2005. radeon_get_encoder_id
  2006. (dev,
  2007. ATOM_DEVICE_DFP1_SUPPORT,
  2008. 0),
  2009. ATOM_DEVICE_DFP1_SUPPORT);
  2010. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2011. }
  2012. radeon_add_legacy_connector(dev,
  2013. i,
  2014. devices,
  2015. legacy_connector_convert
  2016. [connector],
  2017. &ddc_i2c,
  2018. connector_object_id,
  2019. &hpd);
  2020. break;
  2021. case CONNECTOR_DVI_D_LEGACY:
  2022. if ((tmp >> 4) & 0x1) {
  2023. devices = ATOM_DEVICE_DFP2_SUPPORT;
  2024. connector_object_id = combios_check_dl_dvi(dev, 1);
  2025. } else {
  2026. devices = ATOM_DEVICE_DFP1_SUPPORT;
  2027. connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  2028. }
  2029. radeon_add_legacy_encoder(dev,
  2030. radeon_get_encoder_id
  2031. (dev, devices, 0),
  2032. devices);
  2033. radeon_add_legacy_connector(dev, i, devices,
  2034. legacy_connector_convert
  2035. [connector],
  2036. &ddc_i2c,
  2037. connector_object_id,
  2038. &hpd);
  2039. break;
  2040. case CONNECTOR_CTV_LEGACY:
  2041. case CONNECTOR_STV_LEGACY:
  2042. radeon_add_legacy_encoder(dev,
  2043. radeon_get_encoder_id
  2044. (dev,
  2045. ATOM_DEVICE_TV1_SUPPORT,
  2046. 2),
  2047. ATOM_DEVICE_TV1_SUPPORT);
  2048. radeon_add_legacy_connector(dev, i,
  2049. ATOM_DEVICE_TV1_SUPPORT,
  2050. legacy_connector_convert
  2051. [connector],
  2052. &ddc_i2c,
  2053. CONNECTOR_OBJECT_ID_SVIDEO,
  2054. &hpd);
  2055. break;
  2056. default:
  2057. DRM_ERROR("Unknown connector type: %d\n",
  2058. connector);
  2059. continue;
  2060. }
  2061. }
  2062. } else {
  2063. uint16_t tmds_info =
  2064. combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
  2065. if (tmds_info) {
  2066. DRM_DEBUG("Found DFP table, assuming DVI connector\n");
  2067. radeon_add_legacy_encoder(dev,
  2068. radeon_get_encoder_id(dev,
  2069. ATOM_DEVICE_CRT1_SUPPORT,
  2070. 1),
  2071. ATOM_DEVICE_CRT1_SUPPORT);
  2072. radeon_add_legacy_encoder(dev,
  2073. radeon_get_encoder_id(dev,
  2074. ATOM_DEVICE_DFP1_SUPPORT,
  2075. 0),
  2076. ATOM_DEVICE_DFP1_SUPPORT);
  2077. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
  2078. hpd.hpd = RADEON_HPD_1;
  2079. radeon_add_legacy_connector(dev,
  2080. 0,
  2081. ATOM_DEVICE_CRT1_SUPPORT |
  2082. ATOM_DEVICE_DFP1_SUPPORT,
  2083. DRM_MODE_CONNECTOR_DVII,
  2084. &ddc_i2c,
  2085. CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
  2086. &hpd);
  2087. } else {
  2088. uint16_t crt_info =
  2089. combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
  2090. DRM_DEBUG("Found CRT table, assuming VGA connector\n");
  2091. if (crt_info) {
  2092. radeon_add_legacy_encoder(dev,
  2093. radeon_get_encoder_id(dev,
  2094. ATOM_DEVICE_CRT1_SUPPORT,
  2095. 1),
  2096. ATOM_DEVICE_CRT1_SUPPORT);
  2097. ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
  2098. hpd.hpd = RADEON_HPD_NONE;
  2099. radeon_add_legacy_connector(dev,
  2100. 0,
  2101. ATOM_DEVICE_CRT1_SUPPORT,
  2102. DRM_MODE_CONNECTOR_VGA,
  2103. &ddc_i2c,
  2104. CONNECTOR_OBJECT_ID_VGA,
  2105. &hpd);
  2106. } else {
  2107. DRM_DEBUG("No connector info found\n");
  2108. return false;
  2109. }
  2110. }
  2111. }
  2112. if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
  2113. uint16_t lcd_info =
  2114. combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
  2115. if (lcd_info) {
  2116. uint16_t lcd_ddc_info =
  2117. combios_get_table_offset(dev,
  2118. COMBIOS_LCD_DDC_INFO_TABLE);
  2119. radeon_add_legacy_encoder(dev,
  2120. radeon_get_encoder_id(dev,
  2121. ATOM_DEVICE_LCD1_SUPPORT,
  2122. 0),
  2123. ATOM_DEVICE_LCD1_SUPPORT);
  2124. if (lcd_ddc_info) {
  2125. ddc_type = RBIOS8(lcd_ddc_info + 2);
  2126. switch (ddc_type) {
  2127. case DDC_MONID:
  2128. ddc_i2c =
  2129. combios_setup_i2c_bus
  2130. (rdev, RADEON_GPIO_MONID);
  2131. break;
  2132. case DDC_DVI:
  2133. ddc_i2c =
  2134. combios_setup_i2c_bus
  2135. (rdev, RADEON_GPIO_DVI_DDC);
  2136. break;
  2137. case DDC_VGA:
  2138. ddc_i2c =
  2139. combios_setup_i2c_bus
  2140. (rdev, RADEON_GPIO_VGA_DDC);
  2141. break;
  2142. case DDC_CRT2:
  2143. ddc_i2c =
  2144. combios_setup_i2c_bus
  2145. (rdev, RADEON_GPIO_CRT2_DDC);
  2146. break;
  2147. case DDC_LCD:
  2148. ddc_i2c =
  2149. combios_setup_i2c_bus
  2150. (rdev, RADEON_GPIOPAD_MASK);
  2151. ddc_i2c.mask_clk_mask =
  2152. RBIOS32(lcd_ddc_info + 3);
  2153. ddc_i2c.mask_data_mask =
  2154. RBIOS32(lcd_ddc_info + 7);
  2155. ddc_i2c.a_clk_mask =
  2156. RBIOS32(lcd_ddc_info + 3);
  2157. ddc_i2c.a_data_mask =
  2158. RBIOS32(lcd_ddc_info + 7);
  2159. ddc_i2c.en_clk_mask =
  2160. RBIOS32(lcd_ddc_info + 3);
  2161. ddc_i2c.en_data_mask =
  2162. RBIOS32(lcd_ddc_info + 7);
  2163. ddc_i2c.y_clk_mask =
  2164. RBIOS32(lcd_ddc_info + 3);
  2165. ddc_i2c.y_data_mask =
  2166. RBIOS32(lcd_ddc_info + 7);
  2167. break;
  2168. case DDC_GPIO:
  2169. ddc_i2c =
  2170. combios_setup_i2c_bus
  2171. (rdev, RADEON_MDGPIO_MASK);
  2172. ddc_i2c.mask_clk_mask =
  2173. RBIOS32(lcd_ddc_info + 3);
  2174. ddc_i2c.mask_data_mask =
  2175. RBIOS32(lcd_ddc_info + 7);
  2176. ddc_i2c.a_clk_mask =
  2177. RBIOS32(lcd_ddc_info + 3);
  2178. ddc_i2c.a_data_mask =
  2179. RBIOS32(lcd_ddc_info + 7);
  2180. ddc_i2c.en_clk_mask =
  2181. RBIOS32(lcd_ddc_info + 3);
  2182. ddc_i2c.en_data_mask =
  2183. RBIOS32(lcd_ddc_info + 7);
  2184. ddc_i2c.y_clk_mask =
  2185. RBIOS32(lcd_ddc_info + 3);
  2186. ddc_i2c.y_data_mask =
  2187. RBIOS32(lcd_ddc_info + 7);
  2188. break;
  2189. default:
  2190. ddc_i2c.valid = false;
  2191. break;
  2192. }
  2193. DRM_DEBUG("LCD DDC Info Table found!\n");
  2194. } else
  2195. ddc_i2c.valid = false;
  2196. hpd.hpd = RADEON_HPD_NONE;
  2197. radeon_add_legacy_connector(dev,
  2198. 5,
  2199. ATOM_DEVICE_LCD1_SUPPORT,
  2200. DRM_MODE_CONNECTOR_LVDS,
  2201. &ddc_i2c,
  2202. CONNECTOR_OBJECT_ID_LVDS,
  2203. &hpd);
  2204. }
  2205. }
  2206. /* check TV table */
  2207. if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
  2208. uint32_t tv_info =
  2209. combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
  2210. if (tv_info) {
  2211. if (RBIOS8(tv_info + 6) == 'T') {
  2212. if (radeon_apply_legacy_tv_quirks(dev)) {
  2213. hpd.hpd = RADEON_HPD_NONE;
  2214. ddc_i2c.valid = false;
  2215. radeon_add_legacy_encoder(dev,
  2216. radeon_get_encoder_id
  2217. (dev,
  2218. ATOM_DEVICE_TV1_SUPPORT,
  2219. 2),
  2220. ATOM_DEVICE_TV1_SUPPORT);
  2221. radeon_add_legacy_connector(dev, 6,
  2222. ATOM_DEVICE_TV1_SUPPORT,
  2223. DRM_MODE_CONNECTOR_SVIDEO,
  2224. &ddc_i2c,
  2225. CONNECTOR_OBJECT_ID_SVIDEO,
  2226. &hpd);
  2227. }
  2228. }
  2229. }
  2230. }
  2231. radeon_link_encoder_connector(dev);
  2232. return true;
  2233. }
  2234. void radeon_combios_get_power_modes(struct radeon_device *rdev)
  2235. {
  2236. struct drm_device *dev = rdev->ddev;
  2237. u16 offset, misc, misc2 = 0;
  2238. u8 rev, blocks, tmp;
  2239. int state_index = 0;
  2240. rdev->pm.default_power_state_index = -1;
  2241. if (rdev->flags & RADEON_IS_MOBILITY) {
  2242. offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
  2243. if (offset) {
  2244. rev = RBIOS8(offset);
  2245. blocks = RBIOS8(offset + 0x2);
  2246. /* power mode 0 tends to be the only valid one */
  2247. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2248. rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
  2249. rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
  2250. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  2251. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  2252. goto default_mode;
  2253. rdev->pm.power_state[state_index].type =
  2254. POWER_STATE_TYPE_BATTERY;
  2255. misc = RBIOS16(offset + 0x5 + 0x0);
  2256. if (rev > 4)
  2257. misc2 = RBIOS16(offset + 0x5 + 0xe);
  2258. rdev->pm.power_state[state_index].misc = misc;
  2259. rdev->pm.power_state[state_index].misc2 = misc2;
  2260. if (misc & 0x4) {
  2261. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
  2262. if (misc & 0x8)
  2263. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2264. true;
  2265. else
  2266. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  2267. false;
  2268. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
  2269. if (rev < 6) {
  2270. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2271. RBIOS16(offset + 0x5 + 0xb) * 4;
  2272. tmp = RBIOS8(offset + 0x5 + 0xd);
  2273. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2274. } else {
  2275. u8 entries = RBIOS8(offset + 0x5 + 0xb);
  2276. u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
  2277. if (entries && voltage_table_offset) {
  2278. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
  2279. RBIOS16(voltage_table_offset) * 4;
  2280. tmp = RBIOS8(voltage_table_offset + 0x2);
  2281. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
  2282. } else
  2283. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
  2284. }
  2285. switch ((misc2 & 0x700) >> 8) {
  2286. case 0:
  2287. default:
  2288. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
  2289. break;
  2290. case 1:
  2291. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
  2292. break;
  2293. case 2:
  2294. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
  2295. break;
  2296. case 3:
  2297. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
  2298. break;
  2299. case 4:
  2300. rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
  2301. break;
  2302. }
  2303. } else
  2304. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2305. if (rev > 6)
  2306. rdev->pm.power_state[state_index].pcie_lanes =
  2307. RBIOS8(offset + 0x5 + 0x10);
  2308. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2309. state_index++;
  2310. } else {
  2311. /* XXX figure out some good default low power mode for mobility cards w/out power tables */
  2312. }
  2313. } else {
  2314. /* XXX figure out some good default low power mode for desktop cards */
  2315. }
  2316. default_mode:
  2317. /* add the default mode */
  2318. rdev->pm.power_state[state_index].type =
  2319. POWER_STATE_TYPE_DEFAULT;
  2320. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2321. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2322. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2323. rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
  2324. if ((state_index > 0) &&
  2325. (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
  2326. rdev->pm.power_state[state_index].clock_info[0].voltage =
  2327. rdev->pm.power_state[0].clock_info[0].voltage;
  2328. else
  2329. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2330. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2331. rdev->pm.power_state[state_index].flags = 0;
  2332. rdev->pm.default_power_state_index = state_index;
  2333. rdev->pm.num_power_states = state_index + 1;
  2334. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2335. rdev->pm.current_clock_mode_index = 0;
  2336. }
  2337. void radeon_external_tmds_setup(struct drm_encoder *encoder)
  2338. {
  2339. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2340. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2341. if (!tmds)
  2342. return;
  2343. switch (tmds->dvo_chip) {
  2344. case DVO_SIL164:
  2345. /* sil 164 */
  2346. radeon_i2c_put_byte(tmds->i2c_bus,
  2347. tmds->slave_addr,
  2348. 0x08, 0x30);
  2349. radeon_i2c_put_byte(tmds->i2c_bus,
  2350. tmds->slave_addr,
  2351. 0x09, 0x00);
  2352. radeon_i2c_put_byte(tmds->i2c_bus,
  2353. tmds->slave_addr,
  2354. 0x0a, 0x90);
  2355. radeon_i2c_put_byte(tmds->i2c_bus,
  2356. tmds->slave_addr,
  2357. 0x0c, 0x89);
  2358. radeon_i2c_put_byte(tmds->i2c_bus,
  2359. tmds->slave_addr,
  2360. 0x08, 0x3b);
  2361. break;
  2362. case DVO_SIL1178:
  2363. /* sil 1178 - untested */
  2364. /*
  2365. * 0x0f, 0x44
  2366. * 0x0f, 0x4c
  2367. * 0x0e, 0x01
  2368. * 0x0a, 0x80
  2369. * 0x09, 0x30
  2370. * 0x0c, 0xc9
  2371. * 0x0d, 0x70
  2372. * 0x08, 0x32
  2373. * 0x08, 0x33
  2374. */
  2375. break;
  2376. default:
  2377. break;
  2378. }
  2379. }
  2380. bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
  2381. {
  2382. struct drm_device *dev = encoder->dev;
  2383. struct radeon_device *rdev = dev->dev_private;
  2384. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2385. uint16_t offset;
  2386. uint8_t blocks, slave_addr, rev;
  2387. uint32_t index, id;
  2388. uint32_t reg, val, and_mask, or_mask;
  2389. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  2390. if (!tmds)
  2391. return false;
  2392. if (rdev->flags & RADEON_IS_IGP) {
  2393. offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
  2394. rev = RBIOS8(offset);
  2395. if (offset) {
  2396. rev = RBIOS8(offset);
  2397. if (rev > 1) {
  2398. blocks = RBIOS8(offset + 3);
  2399. index = offset + 4;
  2400. while (blocks > 0) {
  2401. id = RBIOS16(index);
  2402. index += 2;
  2403. switch (id >> 13) {
  2404. case 0:
  2405. reg = (id & 0x1fff) * 4;
  2406. val = RBIOS32(index);
  2407. index += 4;
  2408. WREG32(reg, val);
  2409. break;
  2410. case 2:
  2411. reg = (id & 0x1fff) * 4;
  2412. and_mask = RBIOS32(index);
  2413. index += 4;
  2414. or_mask = RBIOS32(index);
  2415. index += 4;
  2416. val = RREG32(reg);
  2417. val = (val & and_mask) | or_mask;
  2418. WREG32(reg, val);
  2419. break;
  2420. case 3:
  2421. val = RBIOS16(index);
  2422. index += 2;
  2423. udelay(val);
  2424. break;
  2425. case 4:
  2426. val = RBIOS16(index);
  2427. index += 2;
  2428. udelay(val * 1000);
  2429. break;
  2430. case 6:
  2431. slave_addr = id & 0xff;
  2432. slave_addr >>= 1; /* 7 bit addressing */
  2433. index++;
  2434. reg = RBIOS8(index);
  2435. index++;
  2436. val = RBIOS8(index);
  2437. index++;
  2438. radeon_i2c_put_byte(tmds->i2c_bus,
  2439. slave_addr,
  2440. reg, val);
  2441. break;
  2442. default:
  2443. DRM_ERROR("Unknown id %d\n", id >> 13);
  2444. break;
  2445. }
  2446. blocks--;
  2447. }
  2448. return true;
  2449. }
  2450. }
  2451. } else {
  2452. offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
  2453. if (offset) {
  2454. index = offset + 10;
  2455. id = RBIOS16(index);
  2456. while (id != 0xffff) {
  2457. index += 2;
  2458. switch (id >> 13) {
  2459. case 0:
  2460. reg = (id & 0x1fff) * 4;
  2461. val = RBIOS32(index);
  2462. WREG32(reg, val);
  2463. break;
  2464. case 2:
  2465. reg = (id & 0x1fff) * 4;
  2466. and_mask = RBIOS32(index);
  2467. index += 4;
  2468. or_mask = RBIOS32(index);
  2469. index += 4;
  2470. val = RREG32(reg);
  2471. val = (val & and_mask) | or_mask;
  2472. WREG32(reg, val);
  2473. break;
  2474. case 4:
  2475. val = RBIOS16(index);
  2476. index += 2;
  2477. udelay(val);
  2478. break;
  2479. case 5:
  2480. reg = id & 0x1fff;
  2481. and_mask = RBIOS32(index);
  2482. index += 4;
  2483. or_mask = RBIOS32(index);
  2484. index += 4;
  2485. val = RREG32_PLL(reg);
  2486. val = (val & and_mask) | or_mask;
  2487. WREG32_PLL(reg, val);
  2488. break;
  2489. case 6:
  2490. reg = id & 0x1fff;
  2491. val = RBIOS8(index);
  2492. index += 1;
  2493. radeon_i2c_put_byte(tmds->i2c_bus,
  2494. tmds->slave_addr,
  2495. reg, val);
  2496. break;
  2497. default:
  2498. DRM_ERROR("Unknown id %d\n", id >> 13);
  2499. break;
  2500. }
  2501. id = RBIOS16(index);
  2502. }
  2503. return true;
  2504. }
  2505. }
  2506. return false;
  2507. }
  2508. static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
  2509. {
  2510. struct radeon_device *rdev = dev->dev_private;
  2511. if (offset) {
  2512. while (RBIOS16(offset)) {
  2513. uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
  2514. uint32_t addr = (RBIOS16(offset) & 0x1fff);
  2515. uint32_t val, and_mask, or_mask;
  2516. uint32_t tmp;
  2517. offset += 2;
  2518. switch (cmd) {
  2519. case 0:
  2520. val = RBIOS32(offset);
  2521. offset += 4;
  2522. WREG32(addr, val);
  2523. break;
  2524. case 1:
  2525. val = RBIOS32(offset);
  2526. offset += 4;
  2527. WREG32(addr, val);
  2528. break;
  2529. case 2:
  2530. and_mask = RBIOS32(offset);
  2531. offset += 4;
  2532. or_mask = RBIOS32(offset);
  2533. offset += 4;
  2534. tmp = RREG32(addr);
  2535. tmp &= and_mask;
  2536. tmp |= or_mask;
  2537. WREG32(addr, tmp);
  2538. break;
  2539. case 3:
  2540. and_mask = RBIOS32(offset);
  2541. offset += 4;
  2542. or_mask = RBIOS32(offset);
  2543. offset += 4;
  2544. tmp = RREG32(addr);
  2545. tmp &= and_mask;
  2546. tmp |= or_mask;
  2547. WREG32(addr, tmp);
  2548. break;
  2549. case 4:
  2550. val = RBIOS16(offset);
  2551. offset += 2;
  2552. udelay(val);
  2553. break;
  2554. case 5:
  2555. val = RBIOS16(offset);
  2556. offset += 2;
  2557. switch (addr) {
  2558. case 8:
  2559. while (val--) {
  2560. if (!
  2561. (RREG32_PLL
  2562. (RADEON_CLK_PWRMGT_CNTL) &
  2563. RADEON_MC_BUSY))
  2564. break;
  2565. }
  2566. break;
  2567. case 9:
  2568. while (val--) {
  2569. if ((RREG32(RADEON_MC_STATUS) &
  2570. RADEON_MC_IDLE))
  2571. break;
  2572. }
  2573. break;
  2574. default:
  2575. break;
  2576. }
  2577. break;
  2578. default:
  2579. break;
  2580. }
  2581. }
  2582. }
  2583. }
  2584. static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
  2585. {
  2586. struct radeon_device *rdev = dev->dev_private;
  2587. if (offset) {
  2588. while (RBIOS8(offset)) {
  2589. uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
  2590. uint8_t addr = (RBIOS8(offset) & 0x3f);
  2591. uint32_t val, shift, tmp;
  2592. uint32_t and_mask, or_mask;
  2593. offset++;
  2594. switch (cmd) {
  2595. case 0:
  2596. val = RBIOS32(offset);
  2597. offset += 4;
  2598. WREG32_PLL(addr, val);
  2599. break;
  2600. case 1:
  2601. shift = RBIOS8(offset) * 8;
  2602. offset++;
  2603. and_mask = RBIOS8(offset) << shift;
  2604. and_mask |= ~(0xff << shift);
  2605. offset++;
  2606. or_mask = RBIOS8(offset) << shift;
  2607. offset++;
  2608. tmp = RREG32_PLL(addr);
  2609. tmp &= and_mask;
  2610. tmp |= or_mask;
  2611. WREG32_PLL(addr, tmp);
  2612. break;
  2613. case 2:
  2614. case 3:
  2615. tmp = 1000;
  2616. switch (addr) {
  2617. case 1:
  2618. udelay(150);
  2619. break;
  2620. case 2:
  2621. udelay(1000);
  2622. break;
  2623. case 3:
  2624. while (tmp--) {
  2625. if (!
  2626. (RREG32_PLL
  2627. (RADEON_CLK_PWRMGT_CNTL) &
  2628. RADEON_MC_BUSY))
  2629. break;
  2630. }
  2631. break;
  2632. case 4:
  2633. while (tmp--) {
  2634. if (RREG32_PLL
  2635. (RADEON_CLK_PWRMGT_CNTL) &
  2636. RADEON_DLL_READY)
  2637. break;
  2638. }
  2639. break;
  2640. case 5:
  2641. tmp =
  2642. RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  2643. if (tmp & RADEON_CG_NO1_DEBUG_0) {
  2644. #if 0
  2645. uint32_t mclk_cntl =
  2646. RREG32_PLL
  2647. (RADEON_MCLK_CNTL);
  2648. mclk_cntl &= 0xffff0000;
  2649. /*mclk_cntl |= 0x00001111;*//* ??? */
  2650. WREG32_PLL(RADEON_MCLK_CNTL,
  2651. mclk_cntl);
  2652. udelay(10000);
  2653. #endif
  2654. WREG32_PLL
  2655. (RADEON_CLK_PWRMGT_CNTL,
  2656. tmp &
  2657. ~RADEON_CG_NO1_DEBUG_0);
  2658. udelay(10000);
  2659. }
  2660. break;
  2661. default:
  2662. break;
  2663. }
  2664. break;
  2665. default:
  2666. break;
  2667. }
  2668. }
  2669. }
  2670. }
  2671. static void combios_parse_ram_reset_table(struct drm_device *dev,
  2672. uint16_t offset)
  2673. {
  2674. struct radeon_device *rdev = dev->dev_private;
  2675. uint32_t tmp;
  2676. if (offset) {
  2677. uint8_t val = RBIOS8(offset);
  2678. while (val != 0xff) {
  2679. offset++;
  2680. if (val == 0x0f) {
  2681. uint32_t channel_complete_mask;
  2682. if (ASIC_IS_R300(rdev))
  2683. channel_complete_mask =
  2684. R300_MEM_PWRUP_COMPLETE;
  2685. else
  2686. channel_complete_mask =
  2687. RADEON_MEM_PWRUP_COMPLETE;
  2688. tmp = 20000;
  2689. while (tmp--) {
  2690. if ((RREG32(RADEON_MEM_STR_CNTL) &
  2691. channel_complete_mask) ==
  2692. channel_complete_mask)
  2693. break;
  2694. }
  2695. } else {
  2696. uint32_t or_mask = RBIOS16(offset);
  2697. offset += 2;
  2698. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2699. tmp &= RADEON_SDRAM_MODE_MASK;
  2700. tmp |= or_mask;
  2701. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2702. or_mask = val << 24;
  2703. tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2704. tmp &= RADEON_B3MEM_RESET_MASK;
  2705. tmp |= or_mask;
  2706. WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
  2707. }
  2708. val = RBIOS8(offset);
  2709. }
  2710. }
  2711. }
  2712. static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
  2713. int mem_addr_mapping)
  2714. {
  2715. struct radeon_device *rdev = dev->dev_private;
  2716. uint32_t mem_cntl;
  2717. uint32_t mem_size;
  2718. uint32_t addr = 0;
  2719. mem_cntl = RREG32(RADEON_MEM_CNTL);
  2720. if (mem_cntl & RV100_HALF_MODE)
  2721. ram /= 2;
  2722. mem_size = ram;
  2723. mem_cntl &= ~(0xff << 8);
  2724. mem_cntl |= (mem_addr_mapping & 0xff) << 8;
  2725. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2726. RREG32(RADEON_MEM_CNTL);
  2727. /* sdram reset ? */
  2728. /* something like this???? */
  2729. while (ram--) {
  2730. addr = ram * 1024 * 1024;
  2731. /* write to each page */
  2732. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2733. WREG32(RADEON_MM_DATA, 0xdeadbeef);
  2734. /* read back and verify */
  2735. WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
  2736. if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
  2737. return 0;
  2738. }
  2739. return mem_size;
  2740. }
  2741. static void combios_write_ram_size(struct drm_device *dev)
  2742. {
  2743. struct radeon_device *rdev = dev->dev_private;
  2744. uint8_t rev;
  2745. uint16_t offset;
  2746. uint32_t mem_size = 0;
  2747. uint32_t mem_cntl = 0;
  2748. /* should do something smarter here I guess... */
  2749. if (rdev->flags & RADEON_IS_IGP)
  2750. return;
  2751. /* first check detected mem table */
  2752. offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
  2753. if (offset) {
  2754. rev = RBIOS8(offset);
  2755. if (rev < 3) {
  2756. mem_cntl = RBIOS32(offset + 1);
  2757. mem_size = RBIOS16(offset + 5);
  2758. if (((rdev->flags & RADEON_FAMILY_MASK) < CHIP_R200) &&
  2759. ((dev->pdev->device != 0x515e)
  2760. && (dev->pdev->device != 0x5969)))
  2761. WREG32(RADEON_MEM_CNTL, mem_cntl);
  2762. }
  2763. }
  2764. if (!mem_size) {
  2765. offset =
  2766. combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
  2767. if (offset) {
  2768. rev = RBIOS8(offset - 1);
  2769. if (rev < 1) {
  2770. if (((rdev->flags & RADEON_FAMILY_MASK) <
  2771. CHIP_R200)
  2772. && ((dev->pdev->device != 0x515e)
  2773. && (dev->pdev->device != 0x5969))) {
  2774. int ram = 0;
  2775. int mem_addr_mapping = 0;
  2776. while (RBIOS8(offset)) {
  2777. ram = RBIOS8(offset);
  2778. mem_addr_mapping =
  2779. RBIOS8(offset + 1);
  2780. if (mem_addr_mapping != 0x25)
  2781. ram *= 2;
  2782. mem_size =
  2783. combios_detect_ram(dev, ram,
  2784. mem_addr_mapping);
  2785. if (mem_size)
  2786. break;
  2787. offset += 2;
  2788. }
  2789. } else
  2790. mem_size = RBIOS8(offset);
  2791. } else {
  2792. mem_size = RBIOS8(offset);
  2793. mem_size *= 2; /* convert to MB */
  2794. }
  2795. }
  2796. }
  2797. mem_size *= (1024 * 1024); /* convert to bytes */
  2798. WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
  2799. }
  2800. void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
  2801. {
  2802. uint16_t dyn_clk_info =
  2803. combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  2804. if (dyn_clk_info)
  2805. combios_parse_pll_table(dev, dyn_clk_info);
  2806. }
  2807. void radeon_combios_asic_init(struct drm_device *dev)
  2808. {
  2809. struct radeon_device *rdev = dev->dev_private;
  2810. uint16_t table;
  2811. /* port hardcoded mac stuff from radeonfb */
  2812. if (rdev->bios == NULL)
  2813. return;
  2814. /* ASIC INIT 1 */
  2815. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
  2816. if (table)
  2817. combios_parse_mmio_table(dev, table);
  2818. /* PLL INIT */
  2819. table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
  2820. if (table)
  2821. combios_parse_pll_table(dev, table);
  2822. /* ASIC INIT 2 */
  2823. table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
  2824. if (table)
  2825. combios_parse_mmio_table(dev, table);
  2826. if (!(rdev->flags & RADEON_IS_IGP)) {
  2827. /* ASIC INIT 4 */
  2828. table =
  2829. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
  2830. if (table)
  2831. combios_parse_mmio_table(dev, table);
  2832. /* RAM RESET */
  2833. table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
  2834. if (table)
  2835. combios_parse_ram_reset_table(dev, table);
  2836. /* ASIC INIT 3 */
  2837. table =
  2838. combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
  2839. if (table)
  2840. combios_parse_mmio_table(dev, table);
  2841. /* write CONFIG_MEMSIZE */
  2842. combios_write_ram_size(dev);
  2843. }
  2844. /* quirk for rs4xx HP nx6125 laptop to make it resume
  2845. * - it hangs on resume inside the dynclk 1 table.
  2846. */
  2847. if (rdev->family == CHIP_RS480 &&
  2848. rdev->pdev->subsystem_vendor == 0x103c &&
  2849. rdev->pdev->subsystem_device == 0x308b)
  2850. return;
  2851. /* quirk for rs4xx HP dv5000 laptop to make it resume
  2852. * - it hangs on resume inside the dynclk 1 table.
  2853. */
  2854. if (rdev->family == CHIP_RS480 &&
  2855. rdev->pdev->subsystem_vendor == 0x103c &&
  2856. rdev->pdev->subsystem_device == 0x30a4)
  2857. return;
  2858. /* DYN CLK 1 */
  2859. table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
  2860. if (table)
  2861. combios_parse_pll_table(dev, table);
  2862. }
  2863. void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
  2864. {
  2865. struct radeon_device *rdev = dev->dev_private;
  2866. uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
  2867. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2868. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2869. bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
  2870. /* let the bios control the backlight */
  2871. bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
  2872. /* tell the bios not to handle mode switching */
  2873. bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
  2874. RADEON_ACC_MODE_CHANGE);
  2875. /* tell the bios a driver is loaded */
  2876. bios_7_scratch |= RADEON_DRV_LOADED;
  2877. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2878. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2879. WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
  2880. }
  2881. void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
  2882. {
  2883. struct drm_device *dev = encoder->dev;
  2884. struct radeon_device *rdev = dev->dev_private;
  2885. uint32_t bios_6_scratch;
  2886. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2887. if (lock)
  2888. bios_6_scratch |= RADEON_DRIVER_CRITICAL;
  2889. else
  2890. bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
  2891. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2892. }
  2893. void
  2894. radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  2895. struct drm_encoder *encoder,
  2896. bool connected)
  2897. {
  2898. struct drm_device *dev = connector->dev;
  2899. struct radeon_device *rdev = dev->dev_private;
  2900. struct radeon_connector *radeon_connector =
  2901. to_radeon_connector(connector);
  2902. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2903. uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
  2904. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  2905. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2906. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2907. if (connected) {
  2908. DRM_DEBUG("TV1 connected\n");
  2909. /* fix me */
  2910. bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
  2911. /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
  2912. bios_5_scratch |= RADEON_TV1_ON;
  2913. bios_5_scratch |= RADEON_ACC_REQ_TV1;
  2914. } else {
  2915. DRM_DEBUG("TV1 disconnected\n");
  2916. bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
  2917. bios_5_scratch &= ~RADEON_TV1_ON;
  2918. bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
  2919. }
  2920. }
  2921. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2922. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2923. if (connected) {
  2924. DRM_DEBUG("LCD1 connected\n");
  2925. bios_4_scratch |= RADEON_LCD1_ATTACHED;
  2926. bios_5_scratch |= RADEON_LCD1_ON;
  2927. bios_5_scratch |= RADEON_ACC_REQ_LCD1;
  2928. } else {
  2929. DRM_DEBUG("LCD1 disconnected\n");
  2930. bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
  2931. bios_5_scratch &= ~RADEON_LCD1_ON;
  2932. bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
  2933. }
  2934. }
  2935. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2936. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2937. if (connected) {
  2938. DRM_DEBUG("CRT1 connected\n");
  2939. bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
  2940. bios_5_scratch |= RADEON_CRT1_ON;
  2941. bios_5_scratch |= RADEON_ACC_REQ_CRT1;
  2942. } else {
  2943. DRM_DEBUG("CRT1 disconnected\n");
  2944. bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
  2945. bios_5_scratch &= ~RADEON_CRT1_ON;
  2946. bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
  2947. }
  2948. }
  2949. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2950. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2951. if (connected) {
  2952. DRM_DEBUG("CRT2 connected\n");
  2953. bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
  2954. bios_5_scratch |= RADEON_CRT2_ON;
  2955. bios_5_scratch |= RADEON_ACC_REQ_CRT2;
  2956. } else {
  2957. DRM_DEBUG("CRT2 disconnected\n");
  2958. bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
  2959. bios_5_scratch &= ~RADEON_CRT2_ON;
  2960. bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
  2961. }
  2962. }
  2963. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2964. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2965. if (connected) {
  2966. DRM_DEBUG("DFP1 connected\n");
  2967. bios_4_scratch |= RADEON_DFP1_ATTACHED;
  2968. bios_5_scratch |= RADEON_DFP1_ON;
  2969. bios_5_scratch |= RADEON_ACC_REQ_DFP1;
  2970. } else {
  2971. DRM_DEBUG("DFP1 disconnected\n");
  2972. bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
  2973. bios_5_scratch &= ~RADEON_DFP1_ON;
  2974. bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
  2975. }
  2976. }
  2977. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2978. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2979. if (connected) {
  2980. DRM_DEBUG("DFP2 connected\n");
  2981. bios_4_scratch |= RADEON_DFP2_ATTACHED;
  2982. bios_5_scratch |= RADEON_DFP2_ON;
  2983. bios_5_scratch |= RADEON_ACC_REQ_DFP2;
  2984. } else {
  2985. DRM_DEBUG("DFP2 disconnected\n");
  2986. bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
  2987. bios_5_scratch &= ~RADEON_DFP2_ON;
  2988. bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
  2989. }
  2990. }
  2991. WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
  2992. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  2993. }
  2994. void
  2995. radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2996. {
  2997. struct drm_device *dev = encoder->dev;
  2998. struct radeon_device *rdev = dev->dev_private;
  2999. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3000. uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
  3001. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3002. bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
  3003. bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
  3004. }
  3005. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3006. bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
  3007. bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
  3008. }
  3009. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3010. bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
  3011. bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
  3012. }
  3013. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3014. bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
  3015. bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
  3016. }
  3017. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3018. bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
  3019. bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
  3020. }
  3021. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3022. bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
  3023. bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
  3024. }
  3025. WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
  3026. }
  3027. void
  3028. radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3029. {
  3030. struct drm_device *dev = encoder->dev;
  3031. struct radeon_device *rdev = dev->dev_private;
  3032. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3033. uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3034. if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
  3035. if (on)
  3036. bios_6_scratch |= RADEON_TV_DPMS_ON;
  3037. else
  3038. bios_6_scratch &= ~RADEON_TV_DPMS_ON;
  3039. }
  3040. if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3041. if (on)
  3042. bios_6_scratch |= RADEON_CRT_DPMS_ON;
  3043. else
  3044. bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
  3045. }
  3046. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3047. if (on)
  3048. bios_6_scratch |= RADEON_LCD_DPMS_ON;
  3049. else
  3050. bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
  3051. }
  3052. if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  3053. if (on)
  3054. bios_6_scratch |= RADEON_DFP_DPMS_ON;
  3055. else
  3056. bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
  3057. }
  3058. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3059. }