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