radeon_atombios.c 89 KB

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