radeon_combios.c 93 KB

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