radeon_atombios.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. /* from radeon_encoder.c */
  32. extern uint32_t
  33. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
  34. uint8_t dac);
  35. extern void radeon_link_encoder_connector(struct drm_device *dev);
  36. extern void
  37. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
  38. uint32_t supported_device, u16 caps);
  39. /* from radeon_connector.c */
  40. extern void
  41. radeon_add_atom_connector(struct drm_device *dev,
  42. uint32_t connector_id,
  43. uint32_t supported_device,
  44. int connector_type,
  45. struct radeon_i2c_bus_rec *i2c_bus,
  46. uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd,
  49. struct radeon_router *router);
  50. /* from radeon_legacy_encoder.c */
  51. extern void
  52. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  53. uint32_t supported_device);
  54. union atom_supported_devices {
  55. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  56. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  57. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  58. };
  59. static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  60. uint8_t id)
  61. {
  62. struct atom_context *ctx = rdev->mode_info.atom_context;
  63. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  64. struct radeon_i2c_bus_rec i2c;
  65. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  66. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  67. uint16_t data_offset, size;
  68. int i, num_indices;
  69. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  70. i2c.valid = false;
  71. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  72. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  73. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  74. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  75. for (i = 0; i < num_indices; i++) {
  76. gpio = &i2c_info->asGPIO_Info[i];
  77. /* some evergreen boards have bad data for this entry */
  78. if (ASIC_IS_DCE4(rdev)) {
  79. if ((i == 7) &&
  80. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
  81. (gpio->sucI2cId.ucAccess == 0)) {
  82. gpio->sucI2cId.ucAccess = 0x97;
  83. gpio->ucDataMaskShift = 8;
  84. gpio->ucDataEnShift = 8;
  85. gpio->ucDataY_Shift = 8;
  86. gpio->ucDataA_Shift = 8;
  87. }
  88. }
  89. /* some DCE3 boards have bad data for this entry */
  90. if (ASIC_IS_DCE3(rdev)) {
  91. if ((i == 4) &&
  92. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
  93. (gpio->sucI2cId.ucAccess == 0x94))
  94. gpio->sucI2cId.ucAccess = 0x14;
  95. }
  96. if (gpio->sucI2cId.ucAccess == id) {
  97. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  98. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  99. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  100. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  101. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  102. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  103. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  104. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  105. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  106. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  107. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  108. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  109. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  110. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  111. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  112. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  113. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  114. i2c.hw_capable = true;
  115. else
  116. i2c.hw_capable = false;
  117. if (gpio->sucI2cId.ucAccess == 0xa0)
  118. i2c.mm_i2c = true;
  119. else
  120. i2c.mm_i2c = false;
  121. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  122. if (i2c.mask_clk_reg)
  123. i2c.valid = true;
  124. break;
  125. }
  126. }
  127. }
  128. return i2c;
  129. }
  130. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  131. {
  132. struct atom_context *ctx = rdev->mode_info.atom_context;
  133. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  134. struct radeon_i2c_bus_rec i2c;
  135. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  136. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  137. uint16_t data_offset, size;
  138. int i, num_indices;
  139. char stmp[32];
  140. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  141. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  142. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  143. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  144. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  145. for (i = 0; i < num_indices; i++) {
  146. gpio = &i2c_info->asGPIO_Info[i];
  147. i2c.valid = false;
  148. /* some evergreen boards have bad data for this entry */
  149. if (ASIC_IS_DCE4(rdev)) {
  150. if ((i == 7) &&
  151. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
  152. (gpio->sucI2cId.ucAccess == 0)) {
  153. gpio->sucI2cId.ucAccess = 0x97;
  154. gpio->ucDataMaskShift = 8;
  155. gpio->ucDataEnShift = 8;
  156. gpio->ucDataY_Shift = 8;
  157. gpio->ucDataA_Shift = 8;
  158. }
  159. }
  160. /* some DCE3 boards have bad data for this entry */
  161. if (ASIC_IS_DCE3(rdev)) {
  162. if ((i == 4) &&
  163. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
  164. (gpio->sucI2cId.ucAccess == 0x94))
  165. gpio->sucI2cId.ucAccess = 0x14;
  166. }
  167. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  168. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  169. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  170. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  171. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  172. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  173. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  174. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  175. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  176. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  177. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  178. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  179. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  180. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  181. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  182. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  183. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  184. i2c.hw_capable = true;
  185. else
  186. i2c.hw_capable = false;
  187. if (gpio->sucI2cId.ucAccess == 0xa0)
  188. i2c.mm_i2c = true;
  189. else
  190. i2c.mm_i2c = false;
  191. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  192. if (i2c.mask_clk_reg) {
  193. i2c.valid = true;
  194. sprintf(stmp, "0x%x", i2c.i2c_id);
  195. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  196. }
  197. }
  198. }
  199. }
  200. static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  201. u8 id)
  202. {
  203. struct atom_context *ctx = rdev->mode_info.atom_context;
  204. struct radeon_gpio_rec gpio;
  205. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  206. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  207. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  208. u16 data_offset, size;
  209. int i, num_indices;
  210. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  211. gpio.valid = false;
  212. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  213. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  214. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  215. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  216. for (i = 0; i < num_indices; i++) {
  217. pin = &gpio_info->asGPIO_Pin[i];
  218. if (id == pin->ucGPIO_ID) {
  219. gpio.id = pin->ucGPIO_ID;
  220. gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
  221. gpio.mask = (1 << pin->ucGpioPinBitShift);
  222. gpio.valid = true;
  223. break;
  224. }
  225. }
  226. }
  227. return gpio;
  228. }
  229. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  230. struct radeon_gpio_rec *gpio)
  231. {
  232. struct radeon_hpd hpd;
  233. u32 reg;
  234. memset(&hpd, 0, sizeof(struct radeon_hpd));
  235. if (ASIC_IS_DCE4(rdev))
  236. reg = EVERGREEN_DC_GPIO_HPD_A;
  237. else
  238. reg = AVIVO_DC_GPIO_HPD_A;
  239. hpd.gpio = *gpio;
  240. if (gpio->reg == reg) {
  241. switch(gpio->mask) {
  242. case (1 << 0):
  243. hpd.hpd = RADEON_HPD_1;
  244. break;
  245. case (1 << 8):
  246. hpd.hpd = RADEON_HPD_2;
  247. break;
  248. case (1 << 16):
  249. hpd.hpd = RADEON_HPD_3;
  250. break;
  251. case (1 << 24):
  252. hpd.hpd = RADEON_HPD_4;
  253. break;
  254. case (1 << 26):
  255. hpd.hpd = RADEON_HPD_5;
  256. break;
  257. case (1 << 28):
  258. hpd.hpd = RADEON_HPD_6;
  259. break;
  260. default:
  261. hpd.hpd = RADEON_HPD_NONE;
  262. break;
  263. }
  264. } else
  265. hpd.hpd = RADEON_HPD_NONE;
  266. return hpd;
  267. }
  268. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  269. uint32_t supported_device,
  270. int *connector_type,
  271. struct radeon_i2c_bus_rec *i2c_bus,
  272. uint16_t *line_mux,
  273. struct radeon_hpd *hpd)
  274. {
  275. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  276. if ((dev->pdev->device == 0x791e) &&
  277. (dev->pdev->subsystem_vendor == 0x1043) &&
  278. (dev->pdev->subsystem_device == 0x826d)) {
  279. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  280. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  281. *connector_type = DRM_MODE_CONNECTOR_DVID;
  282. }
  283. /* Asrock RS600 board lists the DVI port as HDMI */
  284. if ((dev->pdev->device == 0x7941) &&
  285. (dev->pdev->subsystem_vendor == 0x1849) &&
  286. (dev->pdev->subsystem_device == 0x7941)) {
  287. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  288. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  289. *connector_type = DRM_MODE_CONNECTOR_DVID;
  290. }
  291. /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
  292. if ((dev->pdev->device == 0x796e) &&
  293. (dev->pdev->subsystem_vendor == 0x1462) &&
  294. (dev->pdev->subsystem_device == 0x7302)) {
  295. if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
  296. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  297. return false;
  298. }
  299. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  300. if ((dev->pdev->device == 0x7941) &&
  301. (dev->pdev->subsystem_vendor == 0x147b) &&
  302. (dev->pdev->subsystem_device == 0x2412)) {
  303. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  304. return false;
  305. }
  306. /* Falcon NW laptop lists vga ddc line for LVDS */
  307. if ((dev->pdev->device == 0x5653) &&
  308. (dev->pdev->subsystem_vendor == 0x1462) &&
  309. (dev->pdev->subsystem_device == 0x0291)) {
  310. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  311. i2c_bus->valid = false;
  312. *line_mux = 53;
  313. }
  314. }
  315. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  316. if ((dev->pdev->device == 0x7146) &&
  317. (dev->pdev->subsystem_vendor == 0x17af) &&
  318. (dev->pdev->subsystem_device == 0x2058)) {
  319. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  320. return false;
  321. }
  322. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  323. if ((dev->pdev->device == 0x7142) &&
  324. (dev->pdev->subsystem_vendor == 0x1458) &&
  325. (dev->pdev->subsystem_device == 0x2134)) {
  326. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  327. return false;
  328. }
  329. /* Funky macbooks */
  330. if ((dev->pdev->device == 0x71C5) &&
  331. (dev->pdev->subsystem_vendor == 0x106b) &&
  332. (dev->pdev->subsystem_device == 0x0080)) {
  333. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  334. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  335. return false;
  336. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  337. *line_mux = 0x90;
  338. }
  339. /* mac rv630, rv730, others */
  340. if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
  341. (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
  342. *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
  343. *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
  344. }
  345. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  346. if ((dev->pdev->device == 0x9598) &&
  347. (dev->pdev->subsystem_vendor == 0x1043) &&
  348. (dev->pdev->subsystem_device == 0x01da)) {
  349. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  350. *connector_type = DRM_MODE_CONNECTOR_DVII;
  351. }
  352. }
  353. /* ASUS HD 3600 board lists the DVI port as HDMI */
  354. if ((dev->pdev->device == 0x9598) &&
  355. (dev->pdev->subsystem_vendor == 0x1043) &&
  356. (dev->pdev->subsystem_device == 0x01e4)) {
  357. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  358. *connector_type = DRM_MODE_CONNECTOR_DVII;
  359. }
  360. }
  361. /* ASUS HD 3450 board lists the DVI port as HDMI */
  362. if ((dev->pdev->device == 0x95C5) &&
  363. (dev->pdev->subsystem_vendor == 0x1043) &&
  364. (dev->pdev->subsystem_device == 0x01e2)) {
  365. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  366. *connector_type = DRM_MODE_CONNECTOR_DVII;
  367. }
  368. }
  369. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  370. * HDMI + VGA reporting as HDMI
  371. */
  372. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  373. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  374. *connector_type = DRM_MODE_CONNECTOR_VGA;
  375. *line_mux = 0;
  376. }
  377. }
  378. /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
  379. * on the laptop and a DVI port on the docking station and
  380. * both share the same encoder, hpd pin, and ddc line.
  381. * So while the bios table is technically correct,
  382. * we drop the DVI port here since xrandr has no concept of
  383. * encoders and will try and drive both connectors
  384. * with different crtcs which isn't possible on the hardware
  385. * side and leaves no crtcs for LVDS or VGA.
  386. */
  387. if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
  388. (dev->pdev->subsystem_vendor == 0x1025) &&
  389. (dev->pdev->subsystem_device == 0x013c)) {
  390. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  391. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  392. /* actually it's a DVI-D port not DVI-I */
  393. *connector_type = DRM_MODE_CONNECTOR_DVID;
  394. return false;
  395. }
  396. }
  397. /* XFX Pine Group device rv730 reports no VGA DDC lines
  398. * even though they are wired up to record 0x93
  399. */
  400. if ((dev->pdev->device == 0x9498) &&
  401. (dev->pdev->subsystem_vendor == 0x1682) &&
  402. (dev->pdev->subsystem_device == 0x2452)) {
  403. struct radeon_device *rdev = dev->dev_private;
  404. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  405. }
  406. return true;
  407. }
  408. const int supported_devices_connector_convert[] = {
  409. DRM_MODE_CONNECTOR_Unknown,
  410. DRM_MODE_CONNECTOR_VGA,
  411. DRM_MODE_CONNECTOR_DVII,
  412. DRM_MODE_CONNECTOR_DVID,
  413. DRM_MODE_CONNECTOR_DVIA,
  414. DRM_MODE_CONNECTOR_SVIDEO,
  415. DRM_MODE_CONNECTOR_Composite,
  416. DRM_MODE_CONNECTOR_LVDS,
  417. DRM_MODE_CONNECTOR_Unknown,
  418. DRM_MODE_CONNECTOR_Unknown,
  419. DRM_MODE_CONNECTOR_HDMIA,
  420. DRM_MODE_CONNECTOR_HDMIB,
  421. DRM_MODE_CONNECTOR_Unknown,
  422. DRM_MODE_CONNECTOR_Unknown,
  423. DRM_MODE_CONNECTOR_9PinDIN,
  424. DRM_MODE_CONNECTOR_DisplayPort
  425. };
  426. const uint16_t supported_devices_connector_object_id_convert[] = {
  427. CONNECTOR_OBJECT_ID_NONE,
  428. CONNECTOR_OBJECT_ID_VGA,
  429. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  430. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  431. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  432. CONNECTOR_OBJECT_ID_COMPOSITE,
  433. CONNECTOR_OBJECT_ID_SVIDEO,
  434. CONNECTOR_OBJECT_ID_LVDS,
  435. CONNECTOR_OBJECT_ID_9PIN_DIN,
  436. CONNECTOR_OBJECT_ID_9PIN_DIN,
  437. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  438. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  439. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  440. CONNECTOR_OBJECT_ID_SVIDEO
  441. };
  442. const int object_connector_convert[] = {
  443. DRM_MODE_CONNECTOR_Unknown,
  444. DRM_MODE_CONNECTOR_DVII,
  445. DRM_MODE_CONNECTOR_DVII,
  446. DRM_MODE_CONNECTOR_DVID,
  447. DRM_MODE_CONNECTOR_DVID,
  448. DRM_MODE_CONNECTOR_VGA,
  449. DRM_MODE_CONNECTOR_Composite,
  450. DRM_MODE_CONNECTOR_SVIDEO,
  451. DRM_MODE_CONNECTOR_Unknown,
  452. DRM_MODE_CONNECTOR_Unknown,
  453. DRM_MODE_CONNECTOR_9PinDIN,
  454. DRM_MODE_CONNECTOR_Unknown,
  455. DRM_MODE_CONNECTOR_HDMIA,
  456. DRM_MODE_CONNECTOR_HDMIB,
  457. DRM_MODE_CONNECTOR_LVDS,
  458. DRM_MODE_CONNECTOR_9PinDIN,
  459. DRM_MODE_CONNECTOR_Unknown,
  460. DRM_MODE_CONNECTOR_Unknown,
  461. DRM_MODE_CONNECTOR_Unknown,
  462. DRM_MODE_CONNECTOR_DisplayPort,
  463. DRM_MODE_CONNECTOR_eDP,
  464. DRM_MODE_CONNECTOR_Unknown
  465. };
  466. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  467. {
  468. struct radeon_device *rdev = dev->dev_private;
  469. struct radeon_mode_info *mode_info = &rdev->mode_info;
  470. struct atom_context *ctx = mode_info->atom_context;
  471. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  472. u16 size, data_offset;
  473. u8 frev, crev;
  474. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  475. ATOM_ENCODER_OBJECT_TABLE *enc_obj;
  476. ATOM_OBJECT_TABLE *router_obj;
  477. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  478. ATOM_OBJECT_HEADER *obj_header;
  479. int i, j, k, path_size, device_support;
  480. int connector_type;
  481. u16 igp_lane_info, conn_id, connector_object_id;
  482. struct radeon_i2c_bus_rec ddc_bus;
  483. struct radeon_router router;
  484. struct radeon_gpio_rec gpio;
  485. struct radeon_hpd hpd;
  486. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  487. return false;
  488. if (crev < 2)
  489. return false;
  490. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  491. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  492. (ctx->bios + data_offset +
  493. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  494. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  495. (ctx->bios + data_offset +
  496. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  497. enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
  498. (ctx->bios + data_offset +
  499. le16_to_cpu(obj_header->usEncoderObjectTableOffset));
  500. router_obj = (ATOM_OBJECT_TABLE *)
  501. (ctx->bios + data_offset +
  502. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  503. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  504. path_size = 0;
  505. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  506. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  507. ATOM_DISPLAY_OBJECT_PATH *path;
  508. addr += path_size;
  509. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  510. path_size += le16_to_cpu(path->usSize);
  511. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  512. uint8_t con_obj_id, con_obj_num, con_obj_type;
  513. con_obj_id =
  514. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  515. >> OBJECT_ID_SHIFT;
  516. con_obj_num =
  517. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  518. >> ENUM_ID_SHIFT;
  519. con_obj_type =
  520. (le16_to_cpu(path->usConnObjectId) &
  521. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  522. /* TODO CV support */
  523. if (le16_to_cpu(path->usDeviceTag) ==
  524. ATOM_DEVICE_CV_SUPPORT)
  525. continue;
  526. /* IGP chips */
  527. if ((rdev->flags & RADEON_IS_IGP) &&
  528. (con_obj_id ==
  529. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  530. uint16_t igp_offset = 0;
  531. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  532. index =
  533. GetIndexIntoMasterTable(DATA,
  534. IntegratedSystemInfo);
  535. if (atom_parse_data_header(ctx, index, &size, &frev,
  536. &crev, &igp_offset)) {
  537. if (crev >= 2) {
  538. igp_obj =
  539. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  540. *) (ctx->bios + igp_offset);
  541. if (igp_obj) {
  542. uint32_t slot_config, ct;
  543. if (con_obj_num == 1)
  544. slot_config =
  545. igp_obj->
  546. ulDDISlot1Config;
  547. else
  548. slot_config =
  549. igp_obj->
  550. ulDDISlot2Config;
  551. ct = (slot_config >> 16) & 0xff;
  552. connector_type =
  553. object_connector_convert
  554. [ct];
  555. connector_object_id = ct;
  556. igp_lane_info =
  557. slot_config & 0xffff;
  558. } else
  559. continue;
  560. } else
  561. continue;
  562. } else {
  563. igp_lane_info = 0;
  564. connector_type =
  565. object_connector_convert[con_obj_id];
  566. connector_object_id = con_obj_id;
  567. }
  568. } else {
  569. igp_lane_info = 0;
  570. connector_type =
  571. object_connector_convert[con_obj_id];
  572. connector_object_id = con_obj_id;
  573. }
  574. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  575. continue;
  576. router.ddc_valid = false;
  577. router.cd_valid = false;
  578. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  579. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  580. grph_obj_id =
  581. (le16_to_cpu(path->usGraphicObjIds[j]) &
  582. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  583. grph_obj_num =
  584. (le16_to_cpu(path->usGraphicObjIds[j]) &
  585. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  586. grph_obj_type =
  587. (le16_to_cpu(path->usGraphicObjIds[j]) &
  588. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  589. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  590. for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
  591. u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
  592. if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
  593. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  594. (ctx->bios + data_offset +
  595. le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
  596. ATOM_ENCODER_CAP_RECORD *cap_record;
  597. u16 caps = 0;
  598. while (record->ucRecordSize > 0 &&
  599. record->ucRecordType > 0 &&
  600. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  601. switch (record->ucRecordType) {
  602. case ATOM_ENCODER_CAP_RECORD_TYPE:
  603. cap_record =(ATOM_ENCODER_CAP_RECORD *)
  604. record;
  605. caps = le16_to_cpu(cap_record->usEncoderCap);
  606. break;
  607. }
  608. record = (ATOM_COMMON_RECORD_HEADER *)
  609. ((char *)record + record->ucRecordSize);
  610. }
  611. radeon_add_atom_encoder(dev,
  612. encoder_obj,
  613. le16_to_cpu
  614. (path->
  615. usDeviceTag),
  616. caps);
  617. }
  618. }
  619. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  620. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  621. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
  622. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  623. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  624. (ctx->bios + data_offset +
  625. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  626. ATOM_I2C_RECORD *i2c_record;
  627. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  628. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  629. ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
  630. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  631. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  632. (ctx->bios + data_offset +
  633. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  634. int enum_id;
  635. router.router_id = router_obj_id;
  636. for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
  637. enum_id++) {
  638. if (le16_to_cpu(path->usConnObjectId) ==
  639. le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
  640. break;
  641. }
  642. while (record->ucRecordSize > 0 &&
  643. record->ucRecordType > 0 &&
  644. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  645. switch (record->ucRecordType) {
  646. case ATOM_I2C_RECORD_TYPE:
  647. i2c_record =
  648. (ATOM_I2C_RECORD *)
  649. record;
  650. i2c_config =
  651. (ATOM_I2C_ID_CONFIG_ACCESS *)
  652. &i2c_record->sucI2cId;
  653. router.i2c_info =
  654. radeon_lookup_i2c_gpio(rdev,
  655. i2c_config->
  656. ucAccess);
  657. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  658. break;
  659. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  660. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  661. record;
  662. router.ddc_valid = true;
  663. router.ddc_mux_type = ddc_path->ucMuxType;
  664. router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
  665. router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
  666. break;
  667. case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
  668. cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
  669. record;
  670. router.cd_valid = true;
  671. router.cd_mux_type = cd_path->ucMuxType;
  672. router.cd_mux_control_pin = cd_path->ucMuxControlPin;
  673. router.cd_mux_state = cd_path->ucMuxState[enum_id];
  674. break;
  675. }
  676. record = (ATOM_COMMON_RECORD_HEADER *)
  677. ((char *)record + record->ucRecordSize);
  678. }
  679. }
  680. }
  681. }
  682. }
  683. /* look up gpio for ddc, hpd */
  684. ddc_bus.valid = false;
  685. hpd.hpd = RADEON_HPD_NONE;
  686. if ((le16_to_cpu(path->usDeviceTag) &
  687. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  688. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  689. if (le16_to_cpu(path->usConnObjectId) ==
  690. le16_to_cpu(con_obj->asObjects[j].
  691. usObjectID)) {
  692. ATOM_COMMON_RECORD_HEADER
  693. *record =
  694. (ATOM_COMMON_RECORD_HEADER
  695. *)
  696. (ctx->bios + data_offset +
  697. le16_to_cpu(con_obj->
  698. asObjects[j].
  699. usRecordOffset));
  700. ATOM_I2C_RECORD *i2c_record;
  701. ATOM_HPD_INT_RECORD *hpd_record;
  702. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  703. while (record->ucRecordSize > 0 &&
  704. record->ucRecordType > 0 &&
  705. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  706. switch (record->ucRecordType) {
  707. case ATOM_I2C_RECORD_TYPE:
  708. i2c_record =
  709. (ATOM_I2C_RECORD *)
  710. record;
  711. i2c_config =
  712. (ATOM_I2C_ID_CONFIG_ACCESS *)
  713. &i2c_record->sucI2cId;
  714. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  715. i2c_config->
  716. ucAccess);
  717. break;
  718. case ATOM_HPD_INT_RECORD_TYPE:
  719. hpd_record =
  720. (ATOM_HPD_INT_RECORD *)
  721. record;
  722. gpio = radeon_lookup_gpio(rdev,
  723. hpd_record->ucHPDIntGPIOID);
  724. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  725. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  726. break;
  727. }
  728. record =
  729. (ATOM_COMMON_RECORD_HEADER
  730. *) ((char *)record
  731. +
  732. record->
  733. ucRecordSize);
  734. }
  735. break;
  736. }
  737. }
  738. }
  739. /* needed for aux chan transactions */
  740. ddc_bus.hpd = hpd.hpd;
  741. conn_id = le16_to_cpu(path->usConnObjectId);
  742. if (!radeon_atom_apply_quirks
  743. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  744. &ddc_bus, &conn_id, &hpd))
  745. continue;
  746. radeon_add_atom_connector(dev,
  747. conn_id,
  748. le16_to_cpu(path->
  749. usDeviceTag),
  750. connector_type, &ddc_bus,
  751. igp_lane_info,
  752. connector_object_id,
  753. &hpd,
  754. &router);
  755. }
  756. }
  757. radeon_link_encoder_connector(dev);
  758. return true;
  759. }
  760. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  761. int connector_type,
  762. uint16_t devices)
  763. {
  764. struct radeon_device *rdev = dev->dev_private;
  765. if (rdev->flags & RADEON_IS_IGP) {
  766. return supported_devices_connector_object_id_convert
  767. [connector_type];
  768. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  769. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  770. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  771. struct radeon_mode_info *mode_info = &rdev->mode_info;
  772. struct atom_context *ctx = mode_info->atom_context;
  773. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  774. uint16_t size, data_offset;
  775. uint8_t frev, crev;
  776. ATOM_XTMDS_INFO *xtmds;
  777. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  778. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  779. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  780. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  781. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  782. else
  783. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  784. } else {
  785. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  786. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  787. else
  788. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  789. }
  790. } else
  791. return supported_devices_connector_object_id_convert
  792. [connector_type];
  793. } else {
  794. return supported_devices_connector_object_id_convert
  795. [connector_type];
  796. }
  797. }
  798. struct bios_connector {
  799. bool valid;
  800. uint16_t line_mux;
  801. uint16_t devices;
  802. int connector_type;
  803. struct radeon_i2c_bus_rec ddc_bus;
  804. struct radeon_hpd hpd;
  805. };
  806. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  807. drm_device
  808. *dev)
  809. {
  810. struct radeon_device *rdev = dev->dev_private;
  811. struct radeon_mode_info *mode_info = &rdev->mode_info;
  812. struct atom_context *ctx = mode_info->atom_context;
  813. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  814. uint16_t size, data_offset;
  815. uint8_t frev, crev;
  816. uint16_t device_support;
  817. uint8_t dac;
  818. union atom_supported_devices *supported_devices;
  819. int i, j, max_device;
  820. struct bios_connector *bios_connectors;
  821. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  822. struct radeon_router router;
  823. router.ddc_valid = false;
  824. router.cd_valid = false;
  825. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  826. if (!bios_connectors)
  827. return false;
  828. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  829. &data_offset)) {
  830. kfree(bios_connectors);
  831. return false;
  832. }
  833. supported_devices =
  834. (union atom_supported_devices *)(ctx->bios + data_offset);
  835. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  836. if (frev > 1)
  837. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  838. else
  839. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  840. for (i = 0; i < max_device; i++) {
  841. ATOM_CONNECTOR_INFO_I2C ci =
  842. supported_devices->info.asConnInfo[i];
  843. bios_connectors[i].valid = false;
  844. if (!(device_support & (1 << i))) {
  845. continue;
  846. }
  847. if (i == ATOM_DEVICE_CV_INDEX) {
  848. DRM_DEBUG_KMS("Skipping Component Video\n");
  849. continue;
  850. }
  851. bios_connectors[i].connector_type =
  852. supported_devices_connector_convert[ci.sucConnectorInfo.
  853. sbfAccess.
  854. bfConnectorType];
  855. if (bios_connectors[i].connector_type ==
  856. DRM_MODE_CONNECTOR_Unknown)
  857. continue;
  858. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  859. bios_connectors[i].line_mux =
  860. ci.sucI2cId.ucAccess;
  861. /* give tv unique connector ids */
  862. if (i == ATOM_DEVICE_TV1_INDEX) {
  863. bios_connectors[i].ddc_bus.valid = false;
  864. bios_connectors[i].line_mux = 50;
  865. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  866. bios_connectors[i].ddc_bus.valid = false;
  867. bios_connectors[i].line_mux = 51;
  868. } else if (i == ATOM_DEVICE_CV_INDEX) {
  869. bios_connectors[i].ddc_bus.valid = false;
  870. bios_connectors[i].line_mux = 52;
  871. } else
  872. bios_connectors[i].ddc_bus =
  873. radeon_lookup_i2c_gpio(rdev,
  874. bios_connectors[i].line_mux);
  875. if ((crev > 1) && (frev > 1)) {
  876. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  877. switch (isb) {
  878. case 0x4:
  879. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  880. break;
  881. case 0xa:
  882. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  883. break;
  884. default:
  885. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  886. break;
  887. }
  888. } else {
  889. if (i == ATOM_DEVICE_DFP1_INDEX)
  890. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  891. else if (i == ATOM_DEVICE_DFP2_INDEX)
  892. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  893. else
  894. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  895. }
  896. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  897. * shared with a DVI port, we'll pick up the DVI connector when we
  898. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  899. */
  900. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  901. bios_connectors[i].connector_type =
  902. DRM_MODE_CONNECTOR_VGA;
  903. if (!radeon_atom_apply_quirks
  904. (dev, (1 << i), &bios_connectors[i].connector_type,
  905. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  906. &bios_connectors[i].hpd))
  907. continue;
  908. bios_connectors[i].valid = true;
  909. bios_connectors[i].devices = (1 << i);
  910. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  911. radeon_add_atom_encoder(dev,
  912. radeon_get_encoder_enum(dev,
  913. (1 << i),
  914. dac),
  915. (1 << i),
  916. 0);
  917. else
  918. radeon_add_legacy_encoder(dev,
  919. radeon_get_encoder_enum(dev,
  920. (1 << i),
  921. dac),
  922. (1 << i));
  923. }
  924. /* combine shared connectors */
  925. for (i = 0; i < max_device; i++) {
  926. if (bios_connectors[i].valid) {
  927. for (j = 0; j < max_device; j++) {
  928. if (bios_connectors[j].valid && (i != j)) {
  929. if (bios_connectors[i].line_mux ==
  930. bios_connectors[j].line_mux) {
  931. /* make sure not to combine LVDS */
  932. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  933. bios_connectors[i].line_mux = 53;
  934. bios_connectors[i].ddc_bus.valid = false;
  935. continue;
  936. }
  937. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  938. bios_connectors[j].line_mux = 53;
  939. bios_connectors[j].ddc_bus.valid = false;
  940. continue;
  941. }
  942. /* combine analog and digital for DVI-I */
  943. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  944. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  945. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  946. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  947. bios_connectors[i].devices |=
  948. bios_connectors[j].devices;
  949. bios_connectors[i].connector_type =
  950. DRM_MODE_CONNECTOR_DVII;
  951. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  952. bios_connectors[i].hpd =
  953. bios_connectors[j].hpd;
  954. bios_connectors[j].valid = false;
  955. }
  956. }
  957. }
  958. }
  959. }
  960. }
  961. /* add the connectors */
  962. for (i = 0; i < max_device; i++) {
  963. if (bios_connectors[i].valid) {
  964. uint16_t connector_object_id =
  965. atombios_get_connector_object_id(dev,
  966. bios_connectors[i].connector_type,
  967. bios_connectors[i].devices);
  968. radeon_add_atom_connector(dev,
  969. bios_connectors[i].line_mux,
  970. bios_connectors[i].devices,
  971. bios_connectors[i].
  972. connector_type,
  973. &bios_connectors[i].ddc_bus,
  974. 0,
  975. connector_object_id,
  976. &bios_connectors[i].hpd,
  977. &router);
  978. }
  979. }
  980. radeon_link_encoder_connector(dev);
  981. kfree(bios_connectors);
  982. return true;
  983. }
  984. union firmware_info {
  985. ATOM_FIRMWARE_INFO info;
  986. ATOM_FIRMWARE_INFO_V1_2 info_12;
  987. ATOM_FIRMWARE_INFO_V1_3 info_13;
  988. ATOM_FIRMWARE_INFO_V1_4 info_14;
  989. ATOM_FIRMWARE_INFO_V2_1 info_21;
  990. ATOM_FIRMWARE_INFO_V2_2 info_22;
  991. };
  992. bool radeon_atom_get_clock_info(struct drm_device *dev)
  993. {
  994. struct radeon_device *rdev = dev->dev_private;
  995. struct radeon_mode_info *mode_info = &rdev->mode_info;
  996. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  997. union firmware_info *firmware_info;
  998. uint8_t frev, crev;
  999. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  1000. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  1001. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  1002. struct radeon_pll *spll = &rdev->clock.spll;
  1003. struct radeon_pll *mpll = &rdev->clock.mpll;
  1004. uint16_t data_offset;
  1005. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1006. &frev, &crev, &data_offset)) {
  1007. firmware_info =
  1008. (union firmware_info *)(mode_info->atom_context->bios +
  1009. data_offset);
  1010. /* pixel clocks */
  1011. p1pll->reference_freq =
  1012. le16_to_cpu(firmware_info->info.usReferenceClock);
  1013. p1pll->reference_div = 0;
  1014. if (crev < 2)
  1015. p1pll->pll_out_min =
  1016. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  1017. else
  1018. p1pll->pll_out_min =
  1019. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  1020. p1pll->pll_out_max =
  1021. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  1022. if (crev >= 4) {
  1023. p1pll->lcd_pll_out_min =
  1024. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  1025. if (p1pll->lcd_pll_out_min == 0)
  1026. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1027. p1pll->lcd_pll_out_max =
  1028. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  1029. if (p1pll->lcd_pll_out_max == 0)
  1030. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1031. } else {
  1032. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1033. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1034. }
  1035. if (p1pll->pll_out_min == 0) {
  1036. if (ASIC_IS_AVIVO(rdev))
  1037. p1pll->pll_out_min = 64800;
  1038. else
  1039. p1pll->pll_out_min = 20000;
  1040. }
  1041. p1pll->pll_in_min =
  1042. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  1043. p1pll->pll_in_max =
  1044. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  1045. *p2pll = *p1pll;
  1046. /* system clock */
  1047. if (ASIC_IS_DCE4(rdev))
  1048. spll->reference_freq =
  1049. le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
  1050. else
  1051. spll->reference_freq =
  1052. le16_to_cpu(firmware_info->info.usReferenceClock);
  1053. spll->reference_div = 0;
  1054. spll->pll_out_min =
  1055. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1056. spll->pll_out_max =
  1057. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1058. /* ??? */
  1059. if (spll->pll_out_min == 0) {
  1060. if (ASIC_IS_AVIVO(rdev))
  1061. spll->pll_out_min = 64800;
  1062. else
  1063. spll->pll_out_min = 20000;
  1064. }
  1065. spll->pll_in_min =
  1066. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1067. spll->pll_in_max =
  1068. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1069. /* memory clock */
  1070. if (ASIC_IS_DCE4(rdev))
  1071. mpll->reference_freq =
  1072. le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
  1073. else
  1074. mpll->reference_freq =
  1075. le16_to_cpu(firmware_info->info.usReferenceClock);
  1076. mpll->reference_div = 0;
  1077. mpll->pll_out_min =
  1078. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1079. mpll->pll_out_max =
  1080. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1081. /* ??? */
  1082. if (mpll->pll_out_min == 0) {
  1083. if (ASIC_IS_AVIVO(rdev))
  1084. mpll->pll_out_min = 64800;
  1085. else
  1086. mpll->pll_out_min = 20000;
  1087. }
  1088. mpll->pll_in_min =
  1089. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1090. mpll->pll_in_max =
  1091. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1092. rdev->clock.default_sclk =
  1093. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1094. rdev->clock.default_mclk =
  1095. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1096. if (ASIC_IS_DCE4(rdev)) {
  1097. rdev->clock.default_dispclk =
  1098. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1099. if (rdev->clock.default_dispclk == 0) {
  1100. if (ASIC_IS_DCE5(rdev))
  1101. rdev->clock.default_dispclk = 54000; /* 540 Mhz */
  1102. else
  1103. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1104. }
  1105. rdev->clock.dp_extclk =
  1106. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1107. }
  1108. *dcpll = *p1pll;
  1109. rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
  1110. if (rdev->clock.max_pixel_clock == 0)
  1111. rdev->clock.max_pixel_clock = 40000;
  1112. return true;
  1113. }
  1114. return false;
  1115. }
  1116. union igp_info {
  1117. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1118. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1119. };
  1120. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1121. {
  1122. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1123. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1124. union igp_info *igp_info;
  1125. u8 frev, crev;
  1126. u16 data_offset;
  1127. /* sideport is AMD only */
  1128. if (rdev->family == CHIP_RS600)
  1129. return false;
  1130. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1131. &frev, &crev, &data_offset)) {
  1132. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1133. data_offset);
  1134. switch (crev) {
  1135. case 1:
  1136. if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
  1137. return true;
  1138. break;
  1139. case 2:
  1140. if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
  1141. return true;
  1142. break;
  1143. default:
  1144. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1145. break;
  1146. }
  1147. }
  1148. return false;
  1149. }
  1150. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1151. struct radeon_encoder_int_tmds *tmds)
  1152. {
  1153. struct drm_device *dev = encoder->base.dev;
  1154. struct radeon_device *rdev = dev->dev_private;
  1155. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1156. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1157. uint16_t data_offset;
  1158. struct _ATOM_TMDS_INFO *tmds_info;
  1159. uint8_t frev, crev;
  1160. uint16_t maxfreq;
  1161. int i;
  1162. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1163. &frev, &crev, &data_offset)) {
  1164. tmds_info =
  1165. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1166. data_offset);
  1167. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1168. for (i = 0; i < 4; i++) {
  1169. tmds->tmds_pll[i].freq =
  1170. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1171. tmds->tmds_pll[i].value =
  1172. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1173. tmds->tmds_pll[i].value |=
  1174. (tmds_info->asMiscInfo[i].
  1175. ucPLL_VCO_Gain & 0x3f) << 6;
  1176. tmds->tmds_pll[i].value |=
  1177. (tmds_info->asMiscInfo[i].
  1178. ucPLL_DutyCycle & 0xf) << 12;
  1179. tmds->tmds_pll[i].value |=
  1180. (tmds_info->asMiscInfo[i].
  1181. ucPLL_VoltageSwing & 0xf) << 16;
  1182. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1183. tmds->tmds_pll[i].freq,
  1184. tmds->tmds_pll[i].value);
  1185. if (maxfreq == tmds->tmds_pll[i].freq) {
  1186. tmds->tmds_pll[i].freq = 0xffffffff;
  1187. break;
  1188. }
  1189. }
  1190. return true;
  1191. }
  1192. return false;
  1193. }
  1194. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1195. struct radeon_atom_ss *ss,
  1196. int id)
  1197. {
  1198. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1199. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1200. uint16_t data_offset, size;
  1201. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1202. uint8_t frev, crev;
  1203. int i, num_indices;
  1204. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1205. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1206. &frev, &crev, &data_offset)) {
  1207. ss_info =
  1208. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1209. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1210. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1211. for (i = 0; i < num_indices; i++) {
  1212. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1213. ss->percentage =
  1214. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1215. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1216. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1217. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1218. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1219. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1220. return true;
  1221. }
  1222. }
  1223. }
  1224. return false;
  1225. }
  1226. static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
  1227. struct radeon_atom_ss *ss,
  1228. int id)
  1229. {
  1230. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1231. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1232. u16 data_offset, size;
  1233. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
  1234. u8 frev, crev;
  1235. u16 percentage = 0, rate = 0;
  1236. /* get any igp specific overrides */
  1237. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1238. &frev, &crev, &data_offset)) {
  1239. igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
  1240. (mode_info->atom_context->bios + data_offset);
  1241. switch (id) {
  1242. case ASIC_INTERNAL_SS_ON_TMDS:
  1243. percentage = le16_to_cpu(igp_info->usDVISSPercentage);
  1244. rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
  1245. break;
  1246. case ASIC_INTERNAL_SS_ON_HDMI:
  1247. percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
  1248. rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
  1249. break;
  1250. case ASIC_INTERNAL_SS_ON_LVDS:
  1251. percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
  1252. rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
  1253. break;
  1254. }
  1255. if (percentage)
  1256. ss->percentage = percentage;
  1257. if (rate)
  1258. ss->rate = rate;
  1259. }
  1260. }
  1261. union asic_ss_info {
  1262. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1263. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1264. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1265. };
  1266. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1267. struct radeon_atom_ss *ss,
  1268. int id, u32 clock)
  1269. {
  1270. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1271. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1272. uint16_t data_offset, size;
  1273. union asic_ss_info *ss_info;
  1274. uint8_t frev, crev;
  1275. int i, num_indices;
  1276. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1277. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1278. &frev, &crev, &data_offset)) {
  1279. ss_info =
  1280. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1281. switch (frev) {
  1282. case 1:
  1283. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1284. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1285. for (i = 0; i < num_indices; i++) {
  1286. if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
  1287. (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
  1288. ss->percentage =
  1289. le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1290. ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1291. ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
  1292. return true;
  1293. }
  1294. }
  1295. break;
  1296. case 2:
  1297. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1298. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1299. for (i = 0; i < num_indices; i++) {
  1300. if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
  1301. (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
  1302. ss->percentage =
  1303. le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1304. ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1305. ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1306. return true;
  1307. }
  1308. }
  1309. break;
  1310. case 3:
  1311. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1312. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1313. for (i = 0; i < num_indices; i++) {
  1314. if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
  1315. (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
  1316. ss->percentage =
  1317. le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1318. ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1319. ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1320. if (rdev->flags & RADEON_IS_IGP)
  1321. radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
  1322. return true;
  1323. }
  1324. }
  1325. break;
  1326. default:
  1327. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1328. break;
  1329. }
  1330. }
  1331. return false;
  1332. }
  1333. union lvds_info {
  1334. struct _ATOM_LVDS_INFO info;
  1335. struct _ATOM_LVDS_INFO_V12 info_12;
  1336. };
  1337. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1338. radeon_encoder
  1339. *encoder)
  1340. {
  1341. struct drm_device *dev = encoder->base.dev;
  1342. struct radeon_device *rdev = dev->dev_private;
  1343. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1344. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1345. uint16_t data_offset, misc;
  1346. union lvds_info *lvds_info;
  1347. uint8_t frev, crev;
  1348. struct radeon_encoder_atom_dig *lvds = NULL;
  1349. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1350. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1351. &frev, &crev, &data_offset)) {
  1352. lvds_info =
  1353. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1354. lvds =
  1355. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1356. if (!lvds)
  1357. return NULL;
  1358. lvds->native_mode.clock =
  1359. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1360. lvds->native_mode.hdisplay =
  1361. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1362. lvds->native_mode.vdisplay =
  1363. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1364. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1365. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1366. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1367. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1368. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1369. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1370. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1371. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1372. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1373. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1374. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1375. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1376. lvds->panel_pwr_delay =
  1377. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1378. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1379. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1380. if (misc & ATOM_VSYNC_POLARITY)
  1381. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1382. if (misc & ATOM_HSYNC_POLARITY)
  1383. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1384. if (misc & ATOM_COMPOSITESYNC)
  1385. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1386. if (misc & ATOM_INTERLACE)
  1387. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1388. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1389. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1390. lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
  1391. lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
  1392. /* set crtc values */
  1393. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1394. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1395. encoder->native_mode = lvds->native_mode;
  1396. if (encoder_enum == 2)
  1397. lvds->linkb = true;
  1398. else
  1399. lvds->linkb = false;
  1400. /* parse the lcd record table */
  1401. if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
  1402. ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
  1403. ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
  1404. bool bad_record = false;
  1405. u8 *record;
  1406. if ((frev == 1) && (crev < 2))
  1407. /* absolute */
  1408. record = (u8 *)(mode_info->atom_context->bios +
  1409. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1410. else
  1411. /* relative */
  1412. record = (u8 *)(mode_info->atom_context->bios +
  1413. data_offset +
  1414. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1415. while (*record != ATOM_RECORD_END_TYPE) {
  1416. switch (*record) {
  1417. case LCD_MODE_PATCH_RECORD_MODE_TYPE:
  1418. record += sizeof(ATOM_PATCH_RECORD_MODE);
  1419. break;
  1420. case LCD_RTS_RECORD_TYPE:
  1421. record += sizeof(ATOM_LCD_RTS_RECORD);
  1422. break;
  1423. case LCD_CAP_RECORD_TYPE:
  1424. record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
  1425. break;
  1426. case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
  1427. fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
  1428. if (fake_edid_record->ucFakeEDIDLength) {
  1429. struct edid *edid;
  1430. int edid_size =
  1431. max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
  1432. edid = kmalloc(edid_size, GFP_KERNEL);
  1433. if (edid) {
  1434. memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
  1435. fake_edid_record->ucFakeEDIDLength);
  1436. if (drm_edid_is_valid(edid)) {
  1437. rdev->mode_info.bios_hardcoded_edid = edid;
  1438. rdev->mode_info.bios_hardcoded_edid_size = edid_size;
  1439. } else
  1440. kfree(edid);
  1441. }
  1442. }
  1443. record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
  1444. break;
  1445. case LCD_PANEL_RESOLUTION_RECORD_TYPE:
  1446. panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
  1447. lvds->native_mode.width_mm = panel_res_record->usHSize;
  1448. lvds->native_mode.height_mm = panel_res_record->usVSize;
  1449. record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
  1450. break;
  1451. default:
  1452. DRM_ERROR("Bad LCD record %d\n", *record);
  1453. bad_record = true;
  1454. break;
  1455. }
  1456. if (bad_record)
  1457. break;
  1458. }
  1459. }
  1460. }
  1461. return lvds;
  1462. }
  1463. struct radeon_encoder_primary_dac *
  1464. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1465. {
  1466. struct drm_device *dev = encoder->base.dev;
  1467. struct radeon_device *rdev = dev->dev_private;
  1468. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1469. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1470. uint16_t data_offset;
  1471. struct _COMPASSIONATE_DATA *dac_info;
  1472. uint8_t frev, crev;
  1473. uint8_t bg, dac;
  1474. struct radeon_encoder_primary_dac *p_dac = NULL;
  1475. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1476. &frev, &crev, &data_offset)) {
  1477. dac_info = (struct _COMPASSIONATE_DATA *)
  1478. (mode_info->atom_context->bios + data_offset);
  1479. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1480. if (!p_dac)
  1481. return NULL;
  1482. bg = dac_info->ucDAC1_BG_Adjustment;
  1483. dac = dac_info->ucDAC1_DAC_Adjustment;
  1484. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1485. }
  1486. return p_dac;
  1487. }
  1488. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1489. struct drm_display_mode *mode)
  1490. {
  1491. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1492. ATOM_ANALOG_TV_INFO *tv_info;
  1493. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1494. ATOM_DTD_FORMAT *dtd_timings;
  1495. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1496. u8 frev, crev;
  1497. u16 data_offset, misc;
  1498. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1499. &frev, &crev, &data_offset))
  1500. return false;
  1501. switch (crev) {
  1502. case 1:
  1503. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1504. if (index >= MAX_SUPPORTED_TV_TIMING)
  1505. return false;
  1506. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1507. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1508. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1509. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1510. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1511. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1512. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1513. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1514. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1515. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1516. mode->flags = 0;
  1517. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1518. if (misc & ATOM_VSYNC_POLARITY)
  1519. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1520. if (misc & ATOM_HSYNC_POLARITY)
  1521. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1522. if (misc & ATOM_COMPOSITESYNC)
  1523. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1524. if (misc & ATOM_INTERLACE)
  1525. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1526. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1527. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1528. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1529. if (index == 1) {
  1530. /* PAL timings appear to have wrong values for totals */
  1531. mode->crtc_htotal -= 1;
  1532. mode->crtc_vtotal -= 1;
  1533. }
  1534. break;
  1535. case 2:
  1536. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1537. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1538. return false;
  1539. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1540. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1541. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1542. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1543. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1544. le16_to_cpu(dtd_timings->usHSyncOffset);
  1545. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1546. le16_to_cpu(dtd_timings->usHSyncWidth);
  1547. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1548. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1549. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1550. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1551. le16_to_cpu(dtd_timings->usVSyncOffset);
  1552. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1553. le16_to_cpu(dtd_timings->usVSyncWidth);
  1554. mode->flags = 0;
  1555. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1556. if (misc & ATOM_VSYNC_POLARITY)
  1557. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1558. if (misc & ATOM_HSYNC_POLARITY)
  1559. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1560. if (misc & ATOM_COMPOSITESYNC)
  1561. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1562. if (misc & ATOM_INTERLACE)
  1563. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1564. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1565. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1566. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1567. break;
  1568. }
  1569. return true;
  1570. }
  1571. enum radeon_tv_std
  1572. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1573. {
  1574. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1575. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1576. uint16_t data_offset;
  1577. uint8_t frev, crev;
  1578. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1579. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1580. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1581. &frev, &crev, &data_offset)) {
  1582. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1583. (mode_info->atom_context->bios + data_offset);
  1584. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1585. case ATOM_TV_NTSC:
  1586. tv_std = TV_STD_NTSC;
  1587. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1588. break;
  1589. case ATOM_TV_NTSCJ:
  1590. tv_std = TV_STD_NTSC_J;
  1591. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1592. break;
  1593. case ATOM_TV_PAL:
  1594. tv_std = TV_STD_PAL;
  1595. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1596. break;
  1597. case ATOM_TV_PALM:
  1598. tv_std = TV_STD_PAL_M;
  1599. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1600. break;
  1601. case ATOM_TV_PALN:
  1602. tv_std = TV_STD_PAL_N;
  1603. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1604. break;
  1605. case ATOM_TV_PALCN:
  1606. tv_std = TV_STD_PAL_CN;
  1607. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1608. break;
  1609. case ATOM_TV_PAL60:
  1610. tv_std = TV_STD_PAL_60;
  1611. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1612. break;
  1613. case ATOM_TV_SECAM:
  1614. tv_std = TV_STD_SECAM;
  1615. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1616. break;
  1617. default:
  1618. tv_std = TV_STD_NTSC;
  1619. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1620. break;
  1621. }
  1622. }
  1623. return tv_std;
  1624. }
  1625. struct radeon_encoder_tv_dac *
  1626. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1627. {
  1628. struct drm_device *dev = encoder->base.dev;
  1629. struct radeon_device *rdev = dev->dev_private;
  1630. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1631. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1632. uint16_t data_offset;
  1633. struct _COMPASSIONATE_DATA *dac_info;
  1634. uint8_t frev, crev;
  1635. uint8_t bg, dac;
  1636. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1637. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1638. &frev, &crev, &data_offset)) {
  1639. dac_info = (struct _COMPASSIONATE_DATA *)
  1640. (mode_info->atom_context->bios + data_offset);
  1641. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1642. if (!tv_dac)
  1643. return NULL;
  1644. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1645. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1646. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1647. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1648. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1649. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1650. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1651. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1652. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1653. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1654. }
  1655. return tv_dac;
  1656. }
  1657. static const char *thermal_controller_names[] = {
  1658. "NONE",
  1659. "lm63",
  1660. "adm1032",
  1661. "adm1030",
  1662. "max6649",
  1663. "lm64",
  1664. "f75375",
  1665. "asc7xxx",
  1666. };
  1667. static const char *pp_lib_thermal_controller_names[] = {
  1668. "NONE",
  1669. "lm63",
  1670. "adm1032",
  1671. "adm1030",
  1672. "max6649",
  1673. "lm64",
  1674. "f75375",
  1675. "RV6xx",
  1676. "RV770",
  1677. "adt7473",
  1678. "NONE",
  1679. "External GPIO",
  1680. "Evergreen",
  1681. "emc2103",
  1682. "Sumo",
  1683. "Northern Islands",
  1684. };
  1685. union power_info {
  1686. struct _ATOM_POWERPLAY_INFO info;
  1687. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1688. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1689. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1690. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1691. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1692. };
  1693. union pplib_clock_info {
  1694. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1695. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1696. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1697. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1698. };
  1699. union pplib_power_state {
  1700. struct _ATOM_PPLIB_STATE v1;
  1701. struct _ATOM_PPLIB_STATE_V2 v2;
  1702. };
  1703. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1704. int state_index,
  1705. u32 misc, u32 misc2)
  1706. {
  1707. rdev->pm.power_state[state_index].misc = misc;
  1708. rdev->pm.power_state[state_index].misc2 = misc2;
  1709. /* order matters! */
  1710. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1711. rdev->pm.power_state[state_index].type =
  1712. POWER_STATE_TYPE_POWERSAVE;
  1713. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1714. rdev->pm.power_state[state_index].type =
  1715. POWER_STATE_TYPE_BATTERY;
  1716. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1717. rdev->pm.power_state[state_index].type =
  1718. POWER_STATE_TYPE_BATTERY;
  1719. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1720. rdev->pm.power_state[state_index].type =
  1721. POWER_STATE_TYPE_BALANCED;
  1722. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1723. rdev->pm.power_state[state_index].type =
  1724. POWER_STATE_TYPE_PERFORMANCE;
  1725. rdev->pm.power_state[state_index].flags &=
  1726. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1727. }
  1728. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1729. rdev->pm.power_state[state_index].type =
  1730. POWER_STATE_TYPE_BALANCED;
  1731. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1732. rdev->pm.power_state[state_index].type =
  1733. POWER_STATE_TYPE_DEFAULT;
  1734. rdev->pm.default_power_state_index = state_index;
  1735. rdev->pm.power_state[state_index].default_clock_mode =
  1736. &rdev->pm.power_state[state_index].clock_info[0];
  1737. } else if (state_index == 0) {
  1738. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1739. RADEON_PM_MODE_NO_DISPLAY;
  1740. }
  1741. }
  1742. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1743. {
  1744. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1745. u32 misc, misc2 = 0;
  1746. int num_modes = 0, i;
  1747. int state_index = 0;
  1748. struct radeon_i2c_bus_rec i2c_bus;
  1749. union power_info *power_info;
  1750. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1751. u16 data_offset;
  1752. u8 frev, crev;
  1753. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1754. &frev, &crev, &data_offset))
  1755. return state_index;
  1756. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1757. /* add the i2c bus for thermal/fan chip */
  1758. if (power_info->info.ucOverdriveThermalController > 0) {
  1759. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1760. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1761. power_info->info.ucOverdriveControllerAddress >> 1);
  1762. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1763. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1764. if (rdev->pm.i2c_bus) {
  1765. struct i2c_board_info info = { };
  1766. const char *name = thermal_controller_names[power_info->info.
  1767. ucOverdriveThermalController];
  1768. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1769. strlcpy(info.type, name, sizeof(info.type));
  1770. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1771. }
  1772. }
  1773. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1774. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1775. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1776. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
  1777. if (!rdev->pm.power_state)
  1778. return state_index;
  1779. /* last mode is usually default, array is low to high */
  1780. for (i = 0; i < num_modes; i++) {
  1781. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1782. switch (frev) {
  1783. case 1:
  1784. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1785. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1786. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1787. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1788. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1789. /* skip invalid modes */
  1790. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1791. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1792. continue;
  1793. rdev->pm.power_state[state_index].pcie_lanes =
  1794. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1795. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1796. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1797. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1798. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1799. VOLTAGE_GPIO;
  1800. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1801. radeon_lookup_gpio(rdev,
  1802. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1803. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1804. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1805. true;
  1806. else
  1807. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1808. false;
  1809. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1810. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1811. VOLTAGE_VDDC;
  1812. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1813. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1814. }
  1815. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1816. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1817. state_index++;
  1818. break;
  1819. case 2:
  1820. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1821. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1822. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1823. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1824. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1825. /* skip invalid modes */
  1826. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1827. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1828. continue;
  1829. rdev->pm.power_state[state_index].pcie_lanes =
  1830. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1831. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1832. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1833. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1834. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1835. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1836. VOLTAGE_GPIO;
  1837. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1838. radeon_lookup_gpio(rdev,
  1839. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1840. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1841. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1842. true;
  1843. else
  1844. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1845. false;
  1846. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1847. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1848. VOLTAGE_VDDC;
  1849. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1850. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1851. }
  1852. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1853. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1854. state_index++;
  1855. break;
  1856. case 3:
  1857. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1858. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1859. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1860. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1861. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1862. /* skip invalid modes */
  1863. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1864. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1865. continue;
  1866. rdev->pm.power_state[state_index].pcie_lanes =
  1867. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1868. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1869. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1870. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1871. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1872. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1873. VOLTAGE_GPIO;
  1874. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1875. radeon_lookup_gpio(rdev,
  1876. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1877. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1878. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1879. true;
  1880. else
  1881. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1882. false;
  1883. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1884. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1885. VOLTAGE_VDDC;
  1886. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1887. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1888. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1889. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1890. true;
  1891. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1892. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1893. }
  1894. }
  1895. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1896. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1897. state_index++;
  1898. break;
  1899. }
  1900. }
  1901. /* last mode is usually default */
  1902. if (rdev->pm.default_power_state_index == -1) {
  1903. rdev->pm.power_state[state_index - 1].type =
  1904. POWER_STATE_TYPE_DEFAULT;
  1905. rdev->pm.default_power_state_index = state_index - 1;
  1906. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1907. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1908. rdev->pm.power_state[state_index].flags &=
  1909. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1910. rdev->pm.power_state[state_index].misc = 0;
  1911. rdev->pm.power_state[state_index].misc2 = 0;
  1912. }
  1913. return state_index;
  1914. }
  1915. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  1916. ATOM_PPLIB_THERMALCONTROLLER *controller)
  1917. {
  1918. struct radeon_i2c_bus_rec i2c_bus;
  1919. /* add the i2c bus for thermal/fan chip */
  1920. if (controller->ucType > 0) {
  1921. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1922. DRM_INFO("Internal thermal controller %s fan control\n",
  1923. (controller->ucFanParameters &
  1924. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1925. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1926. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1927. DRM_INFO("Internal thermal controller %s fan control\n",
  1928. (controller->ucFanParameters &
  1929. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1930. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1931. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  1932. DRM_INFO("Internal thermal controller %s fan control\n",
  1933. (controller->ucFanParameters &
  1934. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1935. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  1936. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  1937. DRM_INFO("Internal thermal controller %s fan control\n",
  1938. (controller->ucFanParameters &
  1939. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1940. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  1941. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  1942. DRM_INFO("Internal thermal controller %s fan control\n",
  1943. (controller->ucFanParameters &
  1944. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1945. rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
  1946. } else if ((controller->ucType ==
  1947. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1948. (controller->ucType ==
  1949. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
  1950. (controller->ucType ==
  1951. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
  1952. DRM_INFO("Special thermal controller config\n");
  1953. } else {
  1954. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1955. pp_lib_thermal_controller_names[controller->ucType],
  1956. controller->ucI2cAddress >> 1,
  1957. (controller->ucFanParameters &
  1958. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1959. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1960. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1961. if (rdev->pm.i2c_bus) {
  1962. struct i2c_board_info info = { };
  1963. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  1964. info.addr = controller->ucI2cAddress >> 1;
  1965. strlcpy(info.type, name, sizeof(info.type));
  1966. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1967. }
  1968. }
  1969. }
  1970. }
  1971. static void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
  1972. u16 *vddc, u16 *vddci)
  1973. {
  1974. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1975. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  1976. u8 frev, crev;
  1977. u16 data_offset;
  1978. union firmware_info *firmware_info;
  1979. *vddc = 0;
  1980. *vddci = 0;
  1981. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1982. &frev, &crev, &data_offset)) {
  1983. firmware_info =
  1984. (union firmware_info *)(mode_info->atom_context->bios +
  1985. data_offset);
  1986. *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
  1987. if ((frev == 2) && (crev >= 2))
  1988. *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
  1989. }
  1990. }
  1991. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1992. int state_index, int mode_index,
  1993. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  1994. {
  1995. int j;
  1996. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1997. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  1998. u16 vddc, vddci;
  1999. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci);
  2000. rdev->pm.power_state[state_index].misc = misc;
  2001. rdev->pm.power_state[state_index].misc2 = misc2;
  2002. rdev->pm.power_state[state_index].pcie_lanes =
  2003. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  2004. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  2005. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  2006. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  2007. rdev->pm.power_state[state_index].type =
  2008. POWER_STATE_TYPE_BATTERY;
  2009. break;
  2010. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  2011. rdev->pm.power_state[state_index].type =
  2012. POWER_STATE_TYPE_BALANCED;
  2013. break;
  2014. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  2015. rdev->pm.power_state[state_index].type =
  2016. POWER_STATE_TYPE_PERFORMANCE;
  2017. break;
  2018. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  2019. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  2020. rdev->pm.power_state[state_index].type =
  2021. POWER_STATE_TYPE_PERFORMANCE;
  2022. break;
  2023. }
  2024. rdev->pm.power_state[state_index].flags = 0;
  2025. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  2026. rdev->pm.power_state[state_index].flags |=
  2027. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2028. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2029. rdev->pm.power_state[state_index].type =
  2030. POWER_STATE_TYPE_DEFAULT;
  2031. rdev->pm.default_power_state_index = state_index;
  2032. rdev->pm.power_state[state_index].default_clock_mode =
  2033. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  2034. if (ASIC_IS_DCE5(rdev)) {
  2035. /* NI chips post without MC ucode, so default clocks are strobe mode only */
  2036. rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
  2037. rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
  2038. rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
  2039. rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
  2040. } else {
  2041. /* patch the table values with the default slck/mclk from firmware info */
  2042. for (j = 0; j < mode_index; j++) {
  2043. rdev->pm.power_state[state_index].clock_info[j].mclk =
  2044. rdev->clock.default_mclk;
  2045. rdev->pm.power_state[state_index].clock_info[j].sclk =
  2046. rdev->clock.default_sclk;
  2047. if (vddc)
  2048. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  2049. vddc;
  2050. }
  2051. }
  2052. }
  2053. }
  2054. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  2055. int state_index, int mode_index,
  2056. union pplib_clock_info *clock_info)
  2057. {
  2058. u32 sclk, mclk;
  2059. if (rdev->flags & RADEON_IS_IGP) {
  2060. if (rdev->family >= CHIP_PALM) {
  2061. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2062. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2063. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2064. } else {
  2065. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  2066. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  2067. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2068. }
  2069. } else if (ASIC_IS_DCE4(rdev)) {
  2070. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  2071. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  2072. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  2073. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  2074. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2075. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2076. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2077. VOLTAGE_SW;
  2078. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2079. le16_to_cpu(clock_info->evergreen.usVDDC);
  2080. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2081. le16_to_cpu(clock_info->evergreen.usVDDCI);
  2082. } else {
  2083. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  2084. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  2085. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  2086. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  2087. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2088. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2089. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2090. VOLTAGE_SW;
  2091. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2092. le16_to_cpu(clock_info->r600.usVDDC);
  2093. }
  2094. /* patch up vddc if necessary */
  2095. if (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage == 0xff01) {
  2096. u16 vddc;
  2097. if (radeon_atom_get_max_vddc(rdev, &vddc) == 0)
  2098. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
  2099. }
  2100. if (rdev->flags & RADEON_IS_IGP) {
  2101. /* skip invalid modes */
  2102. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  2103. return false;
  2104. } else {
  2105. /* skip invalid modes */
  2106. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  2107. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  2108. return false;
  2109. }
  2110. return true;
  2111. }
  2112. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  2113. {
  2114. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2115. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2116. union pplib_power_state *power_state;
  2117. int i, j;
  2118. int state_index = 0, mode_index = 0;
  2119. union pplib_clock_info *clock_info;
  2120. bool valid;
  2121. union power_info *power_info;
  2122. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2123. u16 data_offset;
  2124. u8 frev, crev;
  2125. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2126. &frev, &crev, &data_offset))
  2127. return state_index;
  2128. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2129. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2130. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2131. power_info->pplib.ucNumStates, GFP_KERNEL);
  2132. if (!rdev->pm.power_state)
  2133. return state_index;
  2134. /* first mode is usually default, followed by low to high */
  2135. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  2136. mode_index = 0;
  2137. power_state = (union pplib_power_state *)
  2138. (mode_info->atom_context->bios + data_offset +
  2139. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  2140. i * power_info->pplib.ucStateEntrySize);
  2141. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2142. (mode_info->atom_context->bios + data_offset +
  2143. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  2144. (power_state->v1.ucNonClockStateIndex *
  2145. power_info->pplib.ucNonClockSize));
  2146. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  2147. clock_info = (union pplib_clock_info *)
  2148. (mode_info->atom_context->bios + data_offset +
  2149. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  2150. (power_state->v1.ucClockStateIndices[j] *
  2151. power_info->pplib.ucClockInfoSize));
  2152. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2153. state_index, mode_index,
  2154. clock_info);
  2155. if (valid)
  2156. mode_index++;
  2157. }
  2158. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2159. if (mode_index) {
  2160. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2161. non_clock_info);
  2162. state_index++;
  2163. }
  2164. }
  2165. /* if multiple clock modes, mark the lowest as no display */
  2166. for (i = 0; i < state_index; i++) {
  2167. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2168. rdev->pm.power_state[i].clock_info[0].flags |=
  2169. RADEON_PM_MODE_NO_DISPLAY;
  2170. }
  2171. /* first mode is usually default */
  2172. if (rdev->pm.default_power_state_index == -1) {
  2173. rdev->pm.power_state[0].type =
  2174. POWER_STATE_TYPE_DEFAULT;
  2175. rdev->pm.default_power_state_index = 0;
  2176. rdev->pm.power_state[0].default_clock_mode =
  2177. &rdev->pm.power_state[0].clock_info[0];
  2178. }
  2179. return state_index;
  2180. }
  2181. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2182. {
  2183. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2184. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2185. union pplib_power_state *power_state;
  2186. int i, j, non_clock_array_index, clock_array_index;
  2187. int state_index = 0, mode_index = 0;
  2188. union pplib_clock_info *clock_info;
  2189. struct StateArray *state_array;
  2190. struct ClockInfoArray *clock_info_array;
  2191. struct NonClockInfoArray *non_clock_info_array;
  2192. bool valid;
  2193. union power_info *power_info;
  2194. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2195. u16 data_offset;
  2196. u8 frev, crev;
  2197. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2198. &frev, &crev, &data_offset))
  2199. return state_index;
  2200. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2201. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2202. state_array = (struct StateArray *)
  2203. (mode_info->atom_context->bios + data_offset +
  2204. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  2205. clock_info_array = (struct ClockInfoArray *)
  2206. (mode_info->atom_context->bios + data_offset +
  2207. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  2208. non_clock_info_array = (struct NonClockInfoArray *)
  2209. (mode_info->atom_context->bios + data_offset +
  2210. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  2211. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2212. state_array->ucNumEntries, GFP_KERNEL);
  2213. if (!rdev->pm.power_state)
  2214. return state_index;
  2215. for (i = 0; i < state_array->ucNumEntries; i++) {
  2216. mode_index = 0;
  2217. power_state = (union pplib_power_state *)&state_array->states[i];
  2218. /* XXX this might be an inagua bug... */
  2219. non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
  2220. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2221. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2222. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2223. clock_array_index = power_state->v2.clockInfoIndex[j];
  2224. /* XXX this might be an inagua bug... */
  2225. if (clock_array_index >= clock_info_array->ucNumEntries)
  2226. continue;
  2227. clock_info = (union pplib_clock_info *)
  2228. &clock_info_array->clockInfo[clock_array_index];
  2229. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2230. state_index, mode_index,
  2231. clock_info);
  2232. if (valid)
  2233. mode_index++;
  2234. }
  2235. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2236. if (mode_index) {
  2237. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2238. non_clock_info);
  2239. state_index++;
  2240. }
  2241. }
  2242. /* if multiple clock modes, mark the lowest as no display */
  2243. for (i = 0; i < state_index; i++) {
  2244. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2245. rdev->pm.power_state[i].clock_info[0].flags |=
  2246. RADEON_PM_MODE_NO_DISPLAY;
  2247. }
  2248. /* first mode is usually default */
  2249. if (rdev->pm.default_power_state_index == -1) {
  2250. rdev->pm.power_state[0].type =
  2251. POWER_STATE_TYPE_DEFAULT;
  2252. rdev->pm.default_power_state_index = 0;
  2253. rdev->pm.power_state[0].default_clock_mode =
  2254. &rdev->pm.power_state[0].clock_info[0];
  2255. }
  2256. return state_index;
  2257. }
  2258. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2259. {
  2260. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2261. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2262. u16 data_offset;
  2263. u8 frev, crev;
  2264. int state_index = 0;
  2265. rdev->pm.default_power_state_index = -1;
  2266. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2267. &frev, &crev, &data_offset)) {
  2268. switch (frev) {
  2269. case 1:
  2270. case 2:
  2271. case 3:
  2272. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2273. break;
  2274. case 4:
  2275. case 5:
  2276. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2277. break;
  2278. case 6:
  2279. state_index = radeon_atombios_parse_power_table_6(rdev);
  2280. break;
  2281. default:
  2282. break;
  2283. }
  2284. } else {
  2285. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
  2286. if (rdev->pm.power_state) {
  2287. /* add the default mode */
  2288. rdev->pm.power_state[state_index].type =
  2289. POWER_STATE_TYPE_DEFAULT;
  2290. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2291. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2292. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2293. rdev->pm.power_state[state_index].default_clock_mode =
  2294. &rdev->pm.power_state[state_index].clock_info[0];
  2295. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2296. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2297. rdev->pm.default_power_state_index = state_index;
  2298. rdev->pm.power_state[state_index].flags = 0;
  2299. state_index++;
  2300. }
  2301. }
  2302. rdev->pm.num_power_states = state_index;
  2303. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2304. rdev->pm.current_clock_mode_index = 0;
  2305. rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2306. }
  2307. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2308. {
  2309. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2310. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2311. args.ucEnable = enable;
  2312. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2313. }
  2314. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2315. {
  2316. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2317. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2318. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2319. return le32_to_cpu(args.ulReturnEngineClock);
  2320. }
  2321. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2322. {
  2323. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2324. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2325. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2326. return le32_to_cpu(args.ulReturnMemoryClock);
  2327. }
  2328. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2329. uint32_t eng_clock)
  2330. {
  2331. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2332. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2333. args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
  2334. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2335. }
  2336. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2337. uint32_t mem_clock)
  2338. {
  2339. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2340. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2341. if (rdev->flags & RADEON_IS_IGP)
  2342. return;
  2343. args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
  2344. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2345. }
  2346. union set_voltage {
  2347. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2348. struct _SET_VOLTAGE_PARAMETERS v1;
  2349. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2350. };
  2351. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
  2352. {
  2353. union set_voltage args;
  2354. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2355. u8 frev, crev, volt_index = voltage_level;
  2356. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2357. return;
  2358. /* 0xff01 is a flag rather then an actual voltage */
  2359. if (voltage_level == 0xff01)
  2360. return;
  2361. switch (crev) {
  2362. case 1:
  2363. args.v1.ucVoltageType = voltage_type;
  2364. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2365. args.v1.ucVoltageIndex = volt_index;
  2366. break;
  2367. case 2:
  2368. args.v2.ucVoltageType = voltage_type;
  2369. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2370. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2371. break;
  2372. default:
  2373. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2374. return;
  2375. }
  2376. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2377. }
  2378. int radeon_atom_get_max_vddc(struct radeon_device *rdev,
  2379. u16 *voltage)
  2380. {
  2381. union set_voltage args;
  2382. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2383. u8 frev, crev;
  2384. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2385. return -EINVAL;
  2386. switch (crev) {
  2387. case 1:
  2388. return -EINVAL;
  2389. case 2:
  2390. args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
  2391. args.v2.ucVoltageMode = 0;
  2392. args.v2.usVoltageLevel = 0;
  2393. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2394. *voltage = le16_to_cpu(args.v2.usVoltageLevel);
  2395. break;
  2396. default:
  2397. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2398. return -EINVAL;
  2399. }
  2400. return 0;
  2401. }
  2402. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2403. {
  2404. struct radeon_device *rdev = dev->dev_private;
  2405. uint32_t bios_2_scratch, bios_6_scratch;
  2406. if (rdev->family >= CHIP_R600) {
  2407. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2408. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2409. } else {
  2410. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2411. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2412. }
  2413. /* let the bios control the backlight */
  2414. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2415. /* tell the bios not to handle mode switching */
  2416. bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
  2417. if (rdev->family >= CHIP_R600) {
  2418. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2419. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2420. } else {
  2421. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2422. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2423. }
  2424. }
  2425. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2426. {
  2427. uint32_t scratch_reg;
  2428. int i;
  2429. if (rdev->family >= CHIP_R600)
  2430. scratch_reg = R600_BIOS_0_SCRATCH;
  2431. else
  2432. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2433. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2434. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2435. }
  2436. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2437. {
  2438. uint32_t scratch_reg;
  2439. int i;
  2440. if (rdev->family >= CHIP_R600)
  2441. scratch_reg = R600_BIOS_0_SCRATCH;
  2442. else
  2443. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2444. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2445. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2446. }
  2447. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2448. {
  2449. struct drm_device *dev = encoder->dev;
  2450. struct radeon_device *rdev = dev->dev_private;
  2451. uint32_t bios_6_scratch;
  2452. if (rdev->family >= CHIP_R600)
  2453. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2454. else
  2455. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2456. if (lock) {
  2457. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2458. bios_6_scratch &= ~ATOM_S6_ACC_MODE;
  2459. } else {
  2460. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2461. bios_6_scratch |= ATOM_S6_ACC_MODE;
  2462. }
  2463. if (rdev->family >= CHIP_R600)
  2464. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2465. else
  2466. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2467. }
  2468. /* at some point we may want to break this out into individual functions */
  2469. void
  2470. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2471. struct drm_encoder *encoder,
  2472. bool connected)
  2473. {
  2474. struct drm_device *dev = connector->dev;
  2475. struct radeon_device *rdev = dev->dev_private;
  2476. struct radeon_connector *radeon_connector =
  2477. to_radeon_connector(connector);
  2478. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2479. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2480. if (rdev->family >= CHIP_R600) {
  2481. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2482. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2483. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2484. } else {
  2485. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2486. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2487. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2488. }
  2489. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2490. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2491. if (connected) {
  2492. DRM_DEBUG_KMS("TV1 connected\n");
  2493. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2494. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2495. } else {
  2496. DRM_DEBUG_KMS("TV1 disconnected\n");
  2497. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2498. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2499. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2500. }
  2501. }
  2502. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2503. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2504. if (connected) {
  2505. DRM_DEBUG_KMS("CV connected\n");
  2506. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2507. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2508. } else {
  2509. DRM_DEBUG_KMS("CV disconnected\n");
  2510. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2511. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2512. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2513. }
  2514. }
  2515. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2516. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2517. if (connected) {
  2518. DRM_DEBUG_KMS("LCD1 connected\n");
  2519. bios_0_scratch |= ATOM_S0_LCD1;
  2520. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2521. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2522. } else {
  2523. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2524. bios_0_scratch &= ~ATOM_S0_LCD1;
  2525. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2526. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2527. }
  2528. }
  2529. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2530. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2531. if (connected) {
  2532. DRM_DEBUG_KMS("CRT1 connected\n");
  2533. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2534. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2535. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2536. } else {
  2537. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2538. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2539. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2540. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2541. }
  2542. }
  2543. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2544. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2545. if (connected) {
  2546. DRM_DEBUG_KMS("CRT2 connected\n");
  2547. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2548. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2549. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2550. } else {
  2551. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2552. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2553. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2554. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2555. }
  2556. }
  2557. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2558. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2559. if (connected) {
  2560. DRM_DEBUG_KMS("DFP1 connected\n");
  2561. bios_0_scratch |= ATOM_S0_DFP1;
  2562. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2563. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2564. } else {
  2565. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2566. bios_0_scratch &= ~ATOM_S0_DFP1;
  2567. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2568. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2569. }
  2570. }
  2571. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2572. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2573. if (connected) {
  2574. DRM_DEBUG_KMS("DFP2 connected\n");
  2575. bios_0_scratch |= ATOM_S0_DFP2;
  2576. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2577. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2578. } else {
  2579. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2580. bios_0_scratch &= ~ATOM_S0_DFP2;
  2581. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2582. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2583. }
  2584. }
  2585. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2586. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2587. if (connected) {
  2588. DRM_DEBUG_KMS("DFP3 connected\n");
  2589. bios_0_scratch |= ATOM_S0_DFP3;
  2590. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2591. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2592. } else {
  2593. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2594. bios_0_scratch &= ~ATOM_S0_DFP3;
  2595. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2596. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2597. }
  2598. }
  2599. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2600. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2601. if (connected) {
  2602. DRM_DEBUG_KMS("DFP4 connected\n");
  2603. bios_0_scratch |= ATOM_S0_DFP4;
  2604. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2605. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2606. } else {
  2607. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2608. bios_0_scratch &= ~ATOM_S0_DFP4;
  2609. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2610. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2611. }
  2612. }
  2613. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2614. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2615. if (connected) {
  2616. DRM_DEBUG_KMS("DFP5 connected\n");
  2617. bios_0_scratch |= ATOM_S0_DFP5;
  2618. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2619. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2620. } else {
  2621. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2622. bios_0_scratch &= ~ATOM_S0_DFP5;
  2623. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2624. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2625. }
  2626. }
  2627. if (rdev->family >= CHIP_R600) {
  2628. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2629. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2630. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2631. } else {
  2632. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2633. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2634. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2635. }
  2636. }
  2637. void
  2638. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2639. {
  2640. struct drm_device *dev = encoder->dev;
  2641. struct radeon_device *rdev = dev->dev_private;
  2642. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2643. uint32_t bios_3_scratch;
  2644. if (rdev->family >= CHIP_R600)
  2645. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2646. else
  2647. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2648. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2649. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2650. bios_3_scratch |= (crtc << 18);
  2651. }
  2652. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2653. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2654. bios_3_scratch |= (crtc << 24);
  2655. }
  2656. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2657. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2658. bios_3_scratch |= (crtc << 16);
  2659. }
  2660. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2661. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2662. bios_3_scratch |= (crtc << 20);
  2663. }
  2664. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2665. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2666. bios_3_scratch |= (crtc << 17);
  2667. }
  2668. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2669. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2670. bios_3_scratch |= (crtc << 19);
  2671. }
  2672. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2673. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2674. bios_3_scratch |= (crtc << 23);
  2675. }
  2676. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2677. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2678. bios_3_scratch |= (crtc << 25);
  2679. }
  2680. if (rdev->family >= CHIP_R600)
  2681. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2682. else
  2683. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2684. }
  2685. void
  2686. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2687. {
  2688. struct drm_device *dev = encoder->dev;
  2689. struct radeon_device *rdev = dev->dev_private;
  2690. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2691. uint32_t bios_2_scratch;
  2692. if (rdev->family >= CHIP_R600)
  2693. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2694. else
  2695. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2696. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2697. if (on)
  2698. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2699. else
  2700. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2701. }
  2702. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2703. if (on)
  2704. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2705. else
  2706. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2707. }
  2708. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2709. if (on)
  2710. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2711. else
  2712. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2713. }
  2714. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2715. if (on)
  2716. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2717. else
  2718. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2719. }
  2720. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2721. if (on)
  2722. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2723. else
  2724. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2725. }
  2726. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2727. if (on)
  2728. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2729. else
  2730. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2731. }
  2732. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2733. if (on)
  2734. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2735. else
  2736. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2737. }
  2738. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2739. if (on)
  2740. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2741. else
  2742. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2743. }
  2744. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2745. if (on)
  2746. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2747. else
  2748. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2749. }
  2750. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2751. if (on)
  2752. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2753. else
  2754. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2755. }
  2756. if (rdev->family >= CHIP_R600)
  2757. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2758. else
  2759. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2760. }