radeon_combios.c 102 KB

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