radeon_combios.c 98 KB

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