radeon_combios.c 85 KB

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