radeon_atombios.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855
  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. /* set crtc values */
  1335. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1336. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1337. encoder->native_mode = lvds->native_mode;
  1338. if (encoder_enum == 2)
  1339. lvds->linkb = true;
  1340. else
  1341. lvds->linkb = false;
  1342. }
  1343. return lvds;
  1344. }
  1345. struct radeon_encoder_primary_dac *
  1346. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1347. {
  1348. struct drm_device *dev = encoder->base.dev;
  1349. struct radeon_device *rdev = dev->dev_private;
  1350. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1351. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1352. uint16_t data_offset;
  1353. struct _COMPASSIONATE_DATA *dac_info;
  1354. uint8_t frev, crev;
  1355. uint8_t bg, dac;
  1356. struct radeon_encoder_primary_dac *p_dac = NULL;
  1357. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1358. &frev, &crev, &data_offset)) {
  1359. dac_info = (struct _COMPASSIONATE_DATA *)
  1360. (mode_info->atom_context->bios + data_offset);
  1361. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1362. if (!p_dac)
  1363. return NULL;
  1364. bg = dac_info->ucDAC1_BG_Adjustment;
  1365. dac = dac_info->ucDAC1_DAC_Adjustment;
  1366. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1367. }
  1368. return p_dac;
  1369. }
  1370. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1371. struct drm_display_mode *mode)
  1372. {
  1373. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1374. ATOM_ANALOG_TV_INFO *tv_info;
  1375. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1376. ATOM_DTD_FORMAT *dtd_timings;
  1377. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1378. u8 frev, crev;
  1379. u16 data_offset, misc;
  1380. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1381. &frev, &crev, &data_offset))
  1382. return false;
  1383. switch (crev) {
  1384. case 1:
  1385. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1386. if (index >= MAX_SUPPORTED_TV_TIMING)
  1387. return false;
  1388. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1389. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1390. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1391. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1392. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1393. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1394. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1395. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1396. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1397. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1398. mode->flags = 0;
  1399. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1400. if (misc & ATOM_VSYNC_POLARITY)
  1401. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1402. if (misc & ATOM_HSYNC_POLARITY)
  1403. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1404. if (misc & ATOM_COMPOSITESYNC)
  1405. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1406. if (misc & ATOM_INTERLACE)
  1407. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1408. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1409. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1410. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1411. if (index == 1) {
  1412. /* PAL timings appear to have wrong values for totals */
  1413. mode->crtc_htotal -= 1;
  1414. mode->crtc_vtotal -= 1;
  1415. }
  1416. break;
  1417. case 2:
  1418. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1419. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1420. return false;
  1421. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1422. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1423. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1424. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1425. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1426. le16_to_cpu(dtd_timings->usHSyncOffset);
  1427. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1428. le16_to_cpu(dtd_timings->usHSyncWidth);
  1429. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1430. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1431. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1432. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1433. le16_to_cpu(dtd_timings->usVSyncOffset);
  1434. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1435. le16_to_cpu(dtd_timings->usVSyncWidth);
  1436. mode->flags = 0;
  1437. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1438. if (misc & ATOM_VSYNC_POLARITY)
  1439. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1440. if (misc & ATOM_HSYNC_POLARITY)
  1441. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1442. if (misc & ATOM_COMPOSITESYNC)
  1443. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1444. if (misc & ATOM_INTERLACE)
  1445. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1446. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1447. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1448. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1449. break;
  1450. }
  1451. return true;
  1452. }
  1453. enum radeon_tv_std
  1454. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1455. {
  1456. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1457. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1458. uint16_t data_offset;
  1459. uint8_t frev, crev;
  1460. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1461. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1462. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1463. &frev, &crev, &data_offset)) {
  1464. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1465. (mode_info->atom_context->bios + data_offset);
  1466. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1467. case ATOM_TV_NTSC:
  1468. tv_std = TV_STD_NTSC;
  1469. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1470. break;
  1471. case ATOM_TV_NTSCJ:
  1472. tv_std = TV_STD_NTSC_J;
  1473. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1474. break;
  1475. case ATOM_TV_PAL:
  1476. tv_std = TV_STD_PAL;
  1477. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1478. break;
  1479. case ATOM_TV_PALM:
  1480. tv_std = TV_STD_PAL_M;
  1481. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1482. break;
  1483. case ATOM_TV_PALN:
  1484. tv_std = TV_STD_PAL_N;
  1485. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1486. break;
  1487. case ATOM_TV_PALCN:
  1488. tv_std = TV_STD_PAL_CN;
  1489. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1490. break;
  1491. case ATOM_TV_PAL60:
  1492. tv_std = TV_STD_PAL_60;
  1493. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1494. break;
  1495. case ATOM_TV_SECAM:
  1496. tv_std = TV_STD_SECAM;
  1497. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1498. break;
  1499. default:
  1500. tv_std = TV_STD_NTSC;
  1501. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1502. break;
  1503. }
  1504. }
  1505. return tv_std;
  1506. }
  1507. struct radeon_encoder_tv_dac *
  1508. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1509. {
  1510. struct drm_device *dev = encoder->base.dev;
  1511. struct radeon_device *rdev = dev->dev_private;
  1512. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1513. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1514. uint16_t data_offset;
  1515. struct _COMPASSIONATE_DATA *dac_info;
  1516. uint8_t frev, crev;
  1517. uint8_t bg, dac;
  1518. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1519. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1520. &frev, &crev, &data_offset)) {
  1521. dac_info = (struct _COMPASSIONATE_DATA *)
  1522. (mode_info->atom_context->bios + data_offset);
  1523. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1524. if (!tv_dac)
  1525. return NULL;
  1526. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1527. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1528. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1529. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1530. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1531. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1532. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1533. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1534. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1535. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1536. }
  1537. return tv_dac;
  1538. }
  1539. static const char *thermal_controller_names[] = {
  1540. "NONE",
  1541. "lm63",
  1542. "adm1032",
  1543. "adm1030",
  1544. "max6649",
  1545. "lm64",
  1546. "f75375",
  1547. "asc7xxx",
  1548. };
  1549. static const char *pp_lib_thermal_controller_names[] = {
  1550. "NONE",
  1551. "lm63",
  1552. "adm1032",
  1553. "adm1030",
  1554. "max6649",
  1555. "lm64",
  1556. "f75375",
  1557. "RV6xx",
  1558. "RV770",
  1559. "adt7473",
  1560. "NONE",
  1561. "External GPIO",
  1562. "Evergreen",
  1563. "emc2103",
  1564. "Sumo",
  1565. };
  1566. union power_info {
  1567. struct _ATOM_POWERPLAY_INFO info;
  1568. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1569. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1570. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1571. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1572. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1573. };
  1574. union pplib_clock_info {
  1575. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1576. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1577. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1578. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1579. };
  1580. union pplib_power_state {
  1581. struct _ATOM_PPLIB_STATE v1;
  1582. struct _ATOM_PPLIB_STATE_V2 v2;
  1583. };
  1584. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1585. int state_index,
  1586. u32 misc, u32 misc2)
  1587. {
  1588. rdev->pm.power_state[state_index].misc = misc;
  1589. rdev->pm.power_state[state_index].misc2 = misc2;
  1590. /* order matters! */
  1591. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1592. rdev->pm.power_state[state_index].type =
  1593. POWER_STATE_TYPE_POWERSAVE;
  1594. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1595. rdev->pm.power_state[state_index].type =
  1596. POWER_STATE_TYPE_BATTERY;
  1597. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1598. rdev->pm.power_state[state_index].type =
  1599. POWER_STATE_TYPE_BATTERY;
  1600. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1601. rdev->pm.power_state[state_index].type =
  1602. POWER_STATE_TYPE_BALANCED;
  1603. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1604. rdev->pm.power_state[state_index].type =
  1605. POWER_STATE_TYPE_PERFORMANCE;
  1606. rdev->pm.power_state[state_index].flags &=
  1607. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1608. }
  1609. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1610. rdev->pm.power_state[state_index].type =
  1611. POWER_STATE_TYPE_BALANCED;
  1612. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1613. rdev->pm.power_state[state_index].type =
  1614. POWER_STATE_TYPE_DEFAULT;
  1615. rdev->pm.default_power_state_index = state_index;
  1616. rdev->pm.power_state[state_index].default_clock_mode =
  1617. &rdev->pm.power_state[state_index].clock_info[0];
  1618. } else if (state_index == 0) {
  1619. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1620. RADEON_PM_MODE_NO_DISPLAY;
  1621. }
  1622. }
  1623. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1624. {
  1625. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1626. u32 misc, misc2 = 0;
  1627. int num_modes = 0, i;
  1628. int state_index = 0;
  1629. struct radeon_i2c_bus_rec i2c_bus;
  1630. union power_info *power_info;
  1631. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1632. u16 data_offset;
  1633. u8 frev, crev;
  1634. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1635. &frev, &crev, &data_offset))
  1636. return state_index;
  1637. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1638. /* add the i2c bus for thermal/fan chip */
  1639. if (power_info->info.ucOverdriveThermalController > 0) {
  1640. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1641. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1642. power_info->info.ucOverdriveControllerAddress >> 1);
  1643. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1644. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1645. if (rdev->pm.i2c_bus) {
  1646. struct i2c_board_info info = { };
  1647. const char *name = thermal_controller_names[power_info->info.
  1648. ucOverdriveThermalController];
  1649. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1650. strlcpy(info.type, name, sizeof(info.type));
  1651. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1652. }
  1653. }
  1654. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1655. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1656. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1657. /* last mode is usually default, array is low to high */
  1658. for (i = 0; i < num_modes; i++) {
  1659. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1660. switch (frev) {
  1661. case 1:
  1662. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1663. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1664. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1665. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1666. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1667. /* skip invalid modes */
  1668. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1669. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1670. continue;
  1671. rdev->pm.power_state[state_index].pcie_lanes =
  1672. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1673. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1674. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1675. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1676. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1677. VOLTAGE_GPIO;
  1678. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1679. radeon_lookup_gpio(rdev,
  1680. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1681. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1682. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1683. true;
  1684. else
  1685. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1686. false;
  1687. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1688. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1689. VOLTAGE_VDDC;
  1690. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1691. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1692. }
  1693. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1694. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1695. state_index++;
  1696. break;
  1697. case 2:
  1698. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1699. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1700. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1701. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1702. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1703. /* skip invalid modes */
  1704. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1705. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1706. continue;
  1707. rdev->pm.power_state[state_index].pcie_lanes =
  1708. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1709. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1710. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1711. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1712. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1713. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1714. VOLTAGE_GPIO;
  1715. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1716. radeon_lookup_gpio(rdev,
  1717. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1718. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1719. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1720. true;
  1721. else
  1722. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1723. false;
  1724. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1725. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1726. VOLTAGE_VDDC;
  1727. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1728. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1729. }
  1730. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1731. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1732. state_index++;
  1733. break;
  1734. case 3:
  1735. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1736. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1737. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1738. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1739. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1740. /* skip invalid modes */
  1741. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1742. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1743. continue;
  1744. rdev->pm.power_state[state_index].pcie_lanes =
  1745. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1746. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1747. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1748. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1749. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1750. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1751. VOLTAGE_GPIO;
  1752. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1753. radeon_lookup_gpio(rdev,
  1754. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1755. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1756. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1757. true;
  1758. else
  1759. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1760. false;
  1761. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1762. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1763. VOLTAGE_VDDC;
  1764. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1765. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1766. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1767. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1768. true;
  1769. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1770. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1771. }
  1772. }
  1773. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1774. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1775. state_index++;
  1776. break;
  1777. }
  1778. }
  1779. /* last mode is usually default */
  1780. if (rdev->pm.default_power_state_index == -1) {
  1781. rdev->pm.power_state[state_index - 1].type =
  1782. POWER_STATE_TYPE_DEFAULT;
  1783. rdev->pm.default_power_state_index = state_index - 1;
  1784. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1785. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1786. rdev->pm.power_state[state_index].flags &=
  1787. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1788. rdev->pm.power_state[state_index].misc = 0;
  1789. rdev->pm.power_state[state_index].misc2 = 0;
  1790. }
  1791. return state_index;
  1792. }
  1793. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  1794. ATOM_PPLIB_THERMALCONTROLLER *controller)
  1795. {
  1796. struct radeon_i2c_bus_rec i2c_bus;
  1797. /* add the i2c bus for thermal/fan chip */
  1798. if (controller->ucType > 0) {
  1799. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1800. DRM_INFO("Internal thermal controller %s fan control\n",
  1801. (controller->ucFanParameters &
  1802. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1803. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1804. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1805. DRM_INFO("Internal thermal controller %s fan control\n",
  1806. (controller->ucFanParameters &
  1807. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1808. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1809. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  1810. DRM_INFO("Internal thermal controller %s fan control\n",
  1811. (controller->ucFanParameters &
  1812. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1813. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  1814. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  1815. DRM_INFO("Internal thermal controller %s fan control\n",
  1816. (controller->ucFanParameters &
  1817. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1818. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  1819. } else if ((controller->ucType ==
  1820. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1821. (controller->ucType ==
  1822. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
  1823. (controller->ucType ==
  1824. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
  1825. DRM_INFO("Special thermal controller config\n");
  1826. } else {
  1827. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1828. pp_lib_thermal_controller_names[controller->ucType],
  1829. controller->ucI2cAddress >> 1,
  1830. (controller->ucFanParameters &
  1831. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1832. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1833. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1834. if (rdev->pm.i2c_bus) {
  1835. struct i2c_board_info info = { };
  1836. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  1837. info.addr = controller->ucI2cAddress >> 1;
  1838. strlcpy(info.type, name, sizeof(info.type));
  1839. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1840. }
  1841. }
  1842. }
  1843. }
  1844. static u16 radeon_atombios_get_default_vddc(struct radeon_device *rdev)
  1845. {
  1846. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1847. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  1848. u8 frev, crev;
  1849. u16 data_offset;
  1850. union firmware_info *firmware_info;
  1851. u16 vddc = 0;
  1852. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1853. &frev, &crev, &data_offset)) {
  1854. firmware_info =
  1855. (union firmware_info *)(mode_info->atom_context->bios +
  1856. data_offset);
  1857. vddc = firmware_info->info_14.usBootUpVDDCVoltage;
  1858. }
  1859. return vddc;
  1860. }
  1861. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1862. int state_index, int mode_index,
  1863. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  1864. {
  1865. int j;
  1866. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1867. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  1868. u16 vddc = radeon_atombios_get_default_vddc(rdev);
  1869. rdev->pm.power_state[state_index].misc = misc;
  1870. rdev->pm.power_state[state_index].misc2 = misc2;
  1871. rdev->pm.power_state[state_index].pcie_lanes =
  1872. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  1873. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  1874. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  1875. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  1876. rdev->pm.power_state[state_index].type =
  1877. POWER_STATE_TYPE_BATTERY;
  1878. break;
  1879. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  1880. rdev->pm.power_state[state_index].type =
  1881. POWER_STATE_TYPE_BALANCED;
  1882. break;
  1883. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  1884. rdev->pm.power_state[state_index].type =
  1885. POWER_STATE_TYPE_PERFORMANCE;
  1886. break;
  1887. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  1888. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  1889. rdev->pm.power_state[state_index].type =
  1890. POWER_STATE_TYPE_PERFORMANCE;
  1891. break;
  1892. }
  1893. rdev->pm.power_state[state_index].flags = 0;
  1894. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  1895. rdev->pm.power_state[state_index].flags |=
  1896. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1897. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1898. rdev->pm.power_state[state_index].type =
  1899. POWER_STATE_TYPE_DEFAULT;
  1900. rdev->pm.default_power_state_index = state_index;
  1901. rdev->pm.power_state[state_index].default_clock_mode =
  1902. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  1903. /* patch the table values with the default slck/mclk from firmware info */
  1904. for (j = 0; j < mode_index; j++) {
  1905. rdev->pm.power_state[state_index].clock_info[j].mclk =
  1906. rdev->clock.default_mclk;
  1907. rdev->pm.power_state[state_index].clock_info[j].sclk =
  1908. rdev->clock.default_sclk;
  1909. if (vddc)
  1910. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  1911. vddc;
  1912. }
  1913. }
  1914. }
  1915. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  1916. int state_index, int mode_index,
  1917. union pplib_clock_info *clock_info)
  1918. {
  1919. u32 sclk, mclk;
  1920. if (rdev->flags & RADEON_IS_IGP) {
  1921. if (rdev->family >= CHIP_PALM) {
  1922. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  1923. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  1924. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1925. } else {
  1926. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  1927. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  1928. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1929. }
  1930. } else if (ASIC_IS_DCE4(rdev)) {
  1931. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  1932. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  1933. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  1934. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  1935. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1936. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1937. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1938. VOLTAGE_SW;
  1939. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1940. clock_info->evergreen.usVDDC;
  1941. } else {
  1942. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  1943. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  1944. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  1945. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  1946. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1947. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1948. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1949. VOLTAGE_SW;
  1950. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1951. clock_info->r600.usVDDC;
  1952. }
  1953. if (rdev->flags & RADEON_IS_IGP) {
  1954. /* skip invalid modes */
  1955. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  1956. return false;
  1957. } else {
  1958. /* skip invalid modes */
  1959. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  1960. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  1961. return false;
  1962. }
  1963. return true;
  1964. }
  1965. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  1966. {
  1967. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1968. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1969. union pplib_power_state *power_state;
  1970. int i, j;
  1971. int state_index = 0, mode_index = 0;
  1972. union pplib_clock_info *clock_info;
  1973. bool valid;
  1974. union power_info *power_info;
  1975. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1976. u16 data_offset;
  1977. u8 frev, crev;
  1978. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1979. &frev, &crev, &data_offset))
  1980. return state_index;
  1981. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1982. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  1983. /* first mode is usually default, followed by low to high */
  1984. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  1985. mode_index = 0;
  1986. power_state = (union pplib_power_state *)
  1987. (mode_info->atom_context->bios + data_offset +
  1988. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  1989. i * power_info->pplib.ucStateEntrySize);
  1990. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1991. (mode_info->atom_context->bios + data_offset +
  1992. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  1993. (power_state->v1.ucNonClockStateIndex *
  1994. power_info->pplib.ucNonClockSize));
  1995. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  1996. clock_info = (union pplib_clock_info *)
  1997. (mode_info->atom_context->bios + data_offset +
  1998. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  1999. (power_state->v1.ucClockStateIndices[j] *
  2000. power_info->pplib.ucClockInfoSize));
  2001. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2002. state_index, mode_index,
  2003. clock_info);
  2004. if (valid)
  2005. mode_index++;
  2006. }
  2007. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2008. if (mode_index) {
  2009. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2010. non_clock_info);
  2011. state_index++;
  2012. }
  2013. }
  2014. /* if multiple clock modes, mark the lowest as no display */
  2015. for (i = 0; i < state_index; i++) {
  2016. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2017. rdev->pm.power_state[i].clock_info[0].flags |=
  2018. RADEON_PM_MODE_NO_DISPLAY;
  2019. }
  2020. /* first mode is usually default */
  2021. if (rdev->pm.default_power_state_index == -1) {
  2022. rdev->pm.power_state[0].type =
  2023. POWER_STATE_TYPE_DEFAULT;
  2024. rdev->pm.default_power_state_index = 0;
  2025. rdev->pm.power_state[0].default_clock_mode =
  2026. &rdev->pm.power_state[0].clock_info[0];
  2027. }
  2028. return state_index;
  2029. }
  2030. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2031. {
  2032. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2033. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2034. union pplib_power_state *power_state;
  2035. int i, j, non_clock_array_index, clock_array_index;
  2036. int state_index = 0, mode_index = 0;
  2037. union pplib_clock_info *clock_info;
  2038. struct StateArray *state_array;
  2039. struct ClockInfoArray *clock_info_array;
  2040. struct NonClockInfoArray *non_clock_info_array;
  2041. bool valid;
  2042. union power_info *power_info;
  2043. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2044. u16 data_offset;
  2045. u8 frev, crev;
  2046. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2047. &frev, &crev, &data_offset))
  2048. return state_index;
  2049. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2050. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2051. state_array = (struct StateArray *)
  2052. (mode_info->atom_context->bios + data_offset +
  2053. power_info->pplib.usStateArrayOffset);
  2054. clock_info_array = (struct ClockInfoArray *)
  2055. (mode_info->atom_context->bios + data_offset +
  2056. power_info->pplib.usClockInfoArrayOffset);
  2057. non_clock_info_array = (struct NonClockInfoArray *)
  2058. (mode_info->atom_context->bios + data_offset +
  2059. power_info->pplib.usNonClockInfoArrayOffset);
  2060. for (i = 0; i < state_array->ucNumEntries; i++) {
  2061. mode_index = 0;
  2062. power_state = (union pplib_power_state *)&state_array->states[i];
  2063. /* XXX this might be an inagua bug... */
  2064. non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
  2065. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2066. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2067. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2068. clock_array_index = power_state->v2.clockInfoIndex[j];
  2069. /* XXX this might be an inagua bug... */
  2070. if (clock_array_index >= clock_info_array->ucNumEntries)
  2071. continue;
  2072. clock_info = (union pplib_clock_info *)
  2073. &clock_info_array->clockInfo[clock_array_index];
  2074. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2075. state_index, mode_index,
  2076. clock_info);
  2077. if (valid)
  2078. mode_index++;
  2079. }
  2080. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2081. if (mode_index) {
  2082. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2083. non_clock_info);
  2084. state_index++;
  2085. }
  2086. }
  2087. /* if multiple clock modes, mark the lowest as no display */
  2088. for (i = 0; i < state_index; i++) {
  2089. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2090. rdev->pm.power_state[i].clock_info[0].flags |=
  2091. RADEON_PM_MODE_NO_DISPLAY;
  2092. }
  2093. /* first mode is usually default */
  2094. if (rdev->pm.default_power_state_index == -1) {
  2095. rdev->pm.power_state[0].type =
  2096. POWER_STATE_TYPE_DEFAULT;
  2097. rdev->pm.default_power_state_index = 0;
  2098. rdev->pm.power_state[0].default_clock_mode =
  2099. &rdev->pm.power_state[0].clock_info[0];
  2100. }
  2101. return state_index;
  2102. }
  2103. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2104. {
  2105. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2106. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2107. u16 data_offset;
  2108. u8 frev, crev;
  2109. int state_index = 0;
  2110. rdev->pm.default_power_state_index = -1;
  2111. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2112. &frev, &crev, &data_offset)) {
  2113. switch (frev) {
  2114. case 1:
  2115. case 2:
  2116. case 3:
  2117. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2118. break;
  2119. case 4:
  2120. case 5:
  2121. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2122. break;
  2123. case 6:
  2124. state_index = radeon_atombios_parse_power_table_6(rdev);
  2125. break;
  2126. default:
  2127. break;
  2128. }
  2129. } else {
  2130. /* add the default mode */
  2131. rdev->pm.power_state[state_index].type =
  2132. POWER_STATE_TYPE_DEFAULT;
  2133. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2134. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2135. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2136. rdev->pm.power_state[state_index].default_clock_mode =
  2137. &rdev->pm.power_state[state_index].clock_info[0];
  2138. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2139. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2140. rdev->pm.default_power_state_index = state_index;
  2141. rdev->pm.power_state[state_index].flags = 0;
  2142. state_index++;
  2143. }
  2144. rdev->pm.num_power_states = state_index;
  2145. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2146. rdev->pm.current_clock_mode_index = 0;
  2147. rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2148. }
  2149. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2150. {
  2151. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2152. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2153. args.ucEnable = enable;
  2154. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2155. }
  2156. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2157. {
  2158. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2159. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2160. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2161. return args.ulReturnEngineClock;
  2162. }
  2163. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2164. {
  2165. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2166. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2167. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2168. return args.ulReturnMemoryClock;
  2169. }
  2170. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2171. uint32_t eng_clock)
  2172. {
  2173. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2174. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2175. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  2176. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2177. }
  2178. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2179. uint32_t mem_clock)
  2180. {
  2181. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2182. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2183. if (rdev->flags & RADEON_IS_IGP)
  2184. return;
  2185. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  2186. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2187. }
  2188. union set_voltage {
  2189. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2190. struct _SET_VOLTAGE_PARAMETERS v1;
  2191. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2192. };
  2193. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
  2194. {
  2195. union set_voltage args;
  2196. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2197. u8 frev, crev, volt_index = level;
  2198. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2199. return;
  2200. switch (crev) {
  2201. case 1:
  2202. args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2203. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2204. args.v1.ucVoltageIndex = volt_index;
  2205. break;
  2206. case 2:
  2207. args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2208. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2209. args.v2.usVoltageLevel = cpu_to_le16(level);
  2210. break;
  2211. default:
  2212. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2213. return;
  2214. }
  2215. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2216. }
  2217. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2218. {
  2219. struct radeon_device *rdev = dev->dev_private;
  2220. uint32_t bios_2_scratch, bios_6_scratch;
  2221. if (rdev->family >= CHIP_R600) {
  2222. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2223. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2224. } else {
  2225. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2226. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2227. }
  2228. /* let the bios control the backlight */
  2229. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2230. /* tell the bios not to handle mode switching */
  2231. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  2232. if (rdev->family >= CHIP_R600) {
  2233. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2234. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2235. } else {
  2236. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2237. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2238. }
  2239. }
  2240. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2241. {
  2242. uint32_t scratch_reg;
  2243. int i;
  2244. if (rdev->family >= CHIP_R600)
  2245. scratch_reg = R600_BIOS_0_SCRATCH;
  2246. else
  2247. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2248. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2249. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2250. }
  2251. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2252. {
  2253. uint32_t scratch_reg;
  2254. int i;
  2255. if (rdev->family >= CHIP_R600)
  2256. scratch_reg = R600_BIOS_0_SCRATCH;
  2257. else
  2258. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2259. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2260. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2261. }
  2262. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2263. {
  2264. struct drm_device *dev = encoder->dev;
  2265. struct radeon_device *rdev = dev->dev_private;
  2266. uint32_t bios_6_scratch;
  2267. if (rdev->family >= CHIP_R600)
  2268. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2269. else
  2270. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2271. if (lock)
  2272. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2273. else
  2274. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2275. if (rdev->family >= CHIP_R600)
  2276. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2277. else
  2278. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2279. }
  2280. /* at some point we may want to break this out into individual functions */
  2281. void
  2282. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2283. struct drm_encoder *encoder,
  2284. bool connected)
  2285. {
  2286. struct drm_device *dev = connector->dev;
  2287. struct radeon_device *rdev = dev->dev_private;
  2288. struct radeon_connector *radeon_connector =
  2289. to_radeon_connector(connector);
  2290. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2291. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2292. if (rdev->family >= CHIP_R600) {
  2293. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2294. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2295. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2296. } else {
  2297. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2298. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2299. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2300. }
  2301. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2302. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2303. if (connected) {
  2304. DRM_DEBUG_KMS("TV1 connected\n");
  2305. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2306. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2307. } else {
  2308. DRM_DEBUG_KMS("TV1 disconnected\n");
  2309. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2310. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2311. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2312. }
  2313. }
  2314. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2315. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2316. if (connected) {
  2317. DRM_DEBUG_KMS("CV connected\n");
  2318. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2319. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2320. } else {
  2321. DRM_DEBUG_KMS("CV disconnected\n");
  2322. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2323. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2324. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2325. }
  2326. }
  2327. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2328. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2329. if (connected) {
  2330. DRM_DEBUG_KMS("LCD1 connected\n");
  2331. bios_0_scratch |= ATOM_S0_LCD1;
  2332. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2333. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2334. } else {
  2335. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2336. bios_0_scratch &= ~ATOM_S0_LCD1;
  2337. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2338. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2339. }
  2340. }
  2341. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2342. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2343. if (connected) {
  2344. DRM_DEBUG_KMS("CRT1 connected\n");
  2345. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2346. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2347. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2348. } else {
  2349. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2350. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2351. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2352. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2353. }
  2354. }
  2355. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2356. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2357. if (connected) {
  2358. DRM_DEBUG_KMS("CRT2 connected\n");
  2359. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2360. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2361. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2362. } else {
  2363. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2364. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2365. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2366. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2367. }
  2368. }
  2369. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2370. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2371. if (connected) {
  2372. DRM_DEBUG_KMS("DFP1 connected\n");
  2373. bios_0_scratch |= ATOM_S0_DFP1;
  2374. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2375. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2376. } else {
  2377. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2378. bios_0_scratch &= ~ATOM_S0_DFP1;
  2379. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2380. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2381. }
  2382. }
  2383. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2384. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2385. if (connected) {
  2386. DRM_DEBUG_KMS("DFP2 connected\n");
  2387. bios_0_scratch |= ATOM_S0_DFP2;
  2388. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2389. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2390. } else {
  2391. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2392. bios_0_scratch &= ~ATOM_S0_DFP2;
  2393. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2394. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2395. }
  2396. }
  2397. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2398. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2399. if (connected) {
  2400. DRM_DEBUG_KMS("DFP3 connected\n");
  2401. bios_0_scratch |= ATOM_S0_DFP3;
  2402. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2403. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2404. } else {
  2405. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2406. bios_0_scratch &= ~ATOM_S0_DFP3;
  2407. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2408. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2409. }
  2410. }
  2411. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2412. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2413. if (connected) {
  2414. DRM_DEBUG_KMS("DFP4 connected\n");
  2415. bios_0_scratch |= ATOM_S0_DFP4;
  2416. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2417. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2418. } else {
  2419. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2420. bios_0_scratch &= ~ATOM_S0_DFP4;
  2421. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2422. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2423. }
  2424. }
  2425. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2426. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2427. if (connected) {
  2428. DRM_DEBUG_KMS("DFP5 connected\n");
  2429. bios_0_scratch |= ATOM_S0_DFP5;
  2430. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2431. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2432. } else {
  2433. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2434. bios_0_scratch &= ~ATOM_S0_DFP5;
  2435. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2436. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2437. }
  2438. }
  2439. if (rdev->family >= CHIP_R600) {
  2440. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2441. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2442. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2443. } else {
  2444. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2445. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2446. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2447. }
  2448. }
  2449. void
  2450. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2451. {
  2452. struct drm_device *dev = encoder->dev;
  2453. struct radeon_device *rdev = dev->dev_private;
  2454. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2455. uint32_t bios_3_scratch;
  2456. if (rdev->family >= CHIP_R600)
  2457. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2458. else
  2459. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2460. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2461. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2462. bios_3_scratch |= (crtc << 18);
  2463. }
  2464. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2465. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2466. bios_3_scratch |= (crtc << 24);
  2467. }
  2468. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2469. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2470. bios_3_scratch |= (crtc << 16);
  2471. }
  2472. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2473. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2474. bios_3_scratch |= (crtc << 20);
  2475. }
  2476. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2477. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2478. bios_3_scratch |= (crtc << 17);
  2479. }
  2480. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2481. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2482. bios_3_scratch |= (crtc << 19);
  2483. }
  2484. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2485. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2486. bios_3_scratch |= (crtc << 23);
  2487. }
  2488. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2489. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2490. bios_3_scratch |= (crtc << 25);
  2491. }
  2492. if (rdev->family >= CHIP_R600)
  2493. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2494. else
  2495. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2496. }
  2497. void
  2498. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2499. {
  2500. struct drm_device *dev = encoder->dev;
  2501. struct radeon_device *rdev = dev->dev_private;
  2502. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2503. uint32_t bios_2_scratch;
  2504. if (rdev->family >= CHIP_R600)
  2505. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2506. else
  2507. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2508. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2509. if (on)
  2510. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2511. else
  2512. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2513. }
  2514. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2515. if (on)
  2516. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2517. else
  2518. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2519. }
  2520. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2521. if (on)
  2522. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2523. else
  2524. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2525. }
  2526. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2527. if (on)
  2528. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2529. else
  2530. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2531. }
  2532. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2533. if (on)
  2534. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2535. else
  2536. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2537. }
  2538. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2539. if (on)
  2540. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2541. else
  2542. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2543. }
  2544. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2545. if (on)
  2546. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2547. else
  2548. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2549. }
  2550. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2551. if (on)
  2552. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2553. else
  2554. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2555. }
  2556. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2557. if (on)
  2558. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2559. else
  2560. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2561. }
  2562. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2563. if (on)
  2564. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2565. else
  2566. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2567. }
  2568. if (rdev->family >= CHIP_R600)
  2569. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2570. else
  2571. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2572. }