radeon_combios.c 85 KB

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