radeon_combios.c 102 KB

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