radeon_combios.c 92 KB

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