radeon_combios.c 102 KB

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