radeon_combios.c 104 KB

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