radeon_combios.c 95 KB

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