radeon_atombios.c 92 KB

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