radeon_atombios.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702
  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. router.valid = false;
  468. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  469. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  470. (ctx->bios + data_offset +
  471. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  472. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  473. (ctx->bios + data_offset +
  474. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  475. router_obj = (ATOM_OBJECT_TABLE *)
  476. (ctx->bios + data_offset +
  477. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  478. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  479. path_size = 0;
  480. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  481. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  482. ATOM_DISPLAY_OBJECT_PATH *path;
  483. addr += path_size;
  484. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  485. path_size += le16_to_cpu(path->usSize);
  486. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  487. uint8_t con_obj_id, con_obj_num, con_obj_type;
  488. con_obj_id =
  489. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  490. >> OBJECT_ID_SHIFT;
  491. con_obj_num =
  492. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  493. >> ENUM_ID_SHIFT;
  494. con_obj_type =
  495. (le16_to_cpu(path->usConnObjectId) &
  496. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  497. /* TODO CV support */
  498. if (le16_to_cpu(path->usDeviceTag) ==
  499. ATOM_DEVICE_CV_SUPPORT)
  500. continue;
  501. /* IGP chips */
  502. if ((rdev->flags & RADEON_IS_IGP) &&
  503. (con_obj_id ==
  504. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  505. uint16_t igp_offset = 0;
  506. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  507. index =
  508. GetIndexIntoMasterTable(DATA,
  509. IntegratedSystemInfo);
  510. if (atom_parse_data_header(ctx, index, &size, &frev,
  511. &crev, &igp_offset)) {
  512. if (crev >= 2) {
  513. igp_obj =
  514. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  515. *) (ctx->bios + igp_offset);
  516. if (igp_obj) {
  517. uint32_t slot_config, ct;
  518. if (con_obj_num == 1)
  519. slot_config =
  520. igp_obj->
  521. ulDDISlot1Config;
  522. else
  523. slot_config =
  524. igp_obj->
  525. ulDDISlot2Config;
  526. ct = (slot_config >> 16) & 0xff;
  527. connector_type =
  528. object_connector_convert
  529. [ct];
  530. connector_object_id = ct;
  531. igp_lane_info =
  532. slot_config & 0xffff;
  533. } else
  534. continue;
  535. } else
  536. continue;
  537. } else {
  538. igp_lane_info = 0;
  539. connector_type =
  540. object_connector_convert[con_obj_id];
  541. connector_object_id = con_obj_id;
  542. }
  543. } else {
  544. igp_lane_info = 0;
  545. connector_type =
  546. object_connector_convert[con_obj_id];
  547. connector_object_id = con_obj_id;
  548. }
  549. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  550. continue;
  551. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  552. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  553. grph_obj_id =
  554. (le16_to_cpu(path->usGraphicObjIds[j]) &
  555. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  556. grph_obj_num =
  557. (le16_to_cpu(path->usGraphicObjIds[j]) &
  558. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  559. grph_obj_type =
  560. (le16_to_cpu(path->usGraphicObjIds[j]) &
  561. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  562. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  563. u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
  564. radeon_add_atom_encoder(dev,
  565. encoder_obj,
  566. le16_to_cpu
  567. (path->
  568. usDeviceTag));
  569. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  570. router.valid = false;
  571. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  572. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].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_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  581. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  582. (ctx->bios + data_offset +
  583. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  584. int enum_id;
  585. router.router_id = router_obj_id;
  586. for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
  587. enum_id++) {
  588. if (le16_to_cpu(path->usConnObjectId) ==
  589. le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
  590. break;
  591. }
  592. while (record->ucRecordType > 0 &&
  593. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  594. switch (record->ucRecordType) {
  595. case ATOM_I2C_RECORD_TYPE:
  596. i2c_record =
  597. (ATOM_I2C_RECORD *)
  598. record;
  599. i2c_config =
  600. (ATOM_I2C_ID_CONFIG_ACCESS *)
  601. &i2c_record->sucI2cId;
  602. router.i2c_info =
  603. radeon_lookup_i2c_gpio(rdev,
  604. i2c_config->
  605. ucAccess);
  606. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  607. break;
  608. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  609. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  610. record;
  611. router.valid = true;
  612. router.mux_type = ddc_path->ucMuxType;
  613. router.mux_control_pin = ddc_path->ucMuxControlPin;
  614. router.mux_state = ddc_path->ucMuxState[enum_id];
  615. break;
  616. }
  617. record = (ATOM_COMMON_RECORD_HEADER *)
  618. ((char *)record + record->ucRecordSize);
  619. }
  620. }
  621. }
  622. }
  623. }
  624. /* look up gpio for ddc, hpd */
  625. ddc_bus.valid = false;
  626. hpd.hpd = RADEON_HPD_NONE;
  627. if ((le16_to_cpu(path->usDeviceTag) &
  628. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  629. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  630. if (le16_to_cpu(path->usConnObjectId) ==
  631. le16_to_cpu(con_obj->asObjects[j].
  632. usObjectID)) {
  633. ATOM_COMMON_RECORD_HEADER
  634. *record =
  635. (ATOM_COMMON_RECORD_HEADER
  636. *)
  637. (ctx->bios + data_offset +
  638. le16_to_cpu(con_obj->
  639. asObjects[j].
  640. usRecordOffset));
  641. ATOM_I2C_RECORD *i2c_record;
  642. ATOM_HPD_INT_RECORD *hpd_record;
  643. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  644. while (record->ucRecordType > 0
  645. && record->
  646. ucRecordType <=
  647. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  648. switch (record->ucRecordType) {
  649. case ATOM_I2C_RECORD_TYPE:
  650. i2c_record =
  651. (ATOM_I2C_RECORD *)
  652. record;
  653. i2c_config =
  654. (ATOM_I2C_ID_CONFIG_ACCESS *)
  655. &i2c_record->sucI2cId;
  656. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  657. i2c_config->
  658. ucAccess);
  659. break;
  660. case ATOM_HPD_INT_RECORD_TYPE:
  661. hpd_record =
  662. (ATOM_HPD_INT_RECORD *)
  663. record;
  664. gpio = radeon_lookup_gpio(rdev,
  665. hpd_record->ucHPDIntGPIOID);
  666. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  667. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  668. break;
  669. }
  670. record =
  671. (ATOM_COMMON_RECORD_HEADER
  672. *) ((char *)record
  673. +
  674. record->
  675. ucRecordSize);
  676. }
  677. break;
  678. }
  679. }
  680. }
  681. /* needed for aux chan transactions */
  682. ddc_bus.hpd = hpd.hpd;
  683. conn_id = le16_to_cpu(path->usConnObjectId);
  684. if (!radeon_atom_apply_quirks
  685. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  686. &ddc_bus, &conn_id, &hpd))
  687. continue;
  688. radeon_add_atom_connector(dev,
  689. conn_id,
  690. le16_to_cpu(path->
  691. usDeviceTag),
  692. connector_type, &ddc_bus,
  693. igp_lane_info,
  694. connector_object_id,
  695. &hpd,
  696. &router);
  697. }
  698. }
  699. radeon_link_encoder_connector(dev);
  700. return true;
  701. }
  702. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  703. int connector_type,
  704. uint16_t devices)
  705. {
  706. struct radeon_device *rdev = dev->dev_private;
  707. if (rdev->flags & RADEON_IS_IGP) {
  708. return supported_devices_connector_object_id_convert
  709. [connector_type];
  710. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  711. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  712. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  713. struct radeon_mode_info *mode_info = &rdev->mode_info;
  714. struct atom_context *ctx = mode_info->atom_context;
  715. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  716. uint16_t size, data_offset;
  717. uint8_t frev, crev;
  718. ATOM_XTMDS_INFO *xtmds;
  719. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  720. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  721. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  722. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  723. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  724. else
  725. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  726. } else {
  727. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  728. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  729. else
  730. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  731. }
  732. } else
  733. return supported_devices_connector_object_id_convert
  734. [connector_type];
  735. } else {
  736. return supported_devices_connector_object_id_convert
  737. [connector_type];
  738. }
  739. }
  740. struct bios_connector {
  741. bool valid;
  742. uint16_t line_mux;
  743. uint16_t devices;
  744. int connector_type;
  745. struct radeon_i2c_bus_rec ddc_bus;
  746. struct radeon_hpd hpd;
  747. };
  748. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  749. drm_device
  750. *dev)
  751. {
  752. struct radeon_device *rdev = dev->dev_private;
  753. struct radeon_mode_info *mode_info = &rdev->mode_info;
  754. struct atom_context *ctx = mode_info->atom_context;
  755. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  756. uint16_t size, data_offset;
  757. uint8_t frev, crev;
  758. uint16_t device_support;
  759. uint8_t dac;
  760. union atom_supported_devices *supported_devices;
  761. int i, j, max_device;
  762. struct bios_connector *bios_connectors;
  763. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  764. struct radeon_router router;
  765. router.valid = false;
  766. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  767. if (!bios_connectors)
  768. return false;
  769. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  770. &data_offset)) {
  771. kfree(bios_connectors);
  772. return false;
  773. }
  774. supported_devices =
  775. (union atom_supported_devices *)(ctx->bios + data_offset);
  776. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  777. if (frev > 1)
  778. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  779. else
  780. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  781. for (i = 0; i < max_device; i++) {
  782. ATOM_CONNECTOR_INFO_I2C ci =
  783. supported_devices->info.asConnInfo[i];
  784. bios_connectors[i].valid = false;
  785. if (!(device_support & (1 << i))) {
  786. continue;
  787. }
  788. if (i == ATOM_DEVICE_CV_INDEX) {
  789. DRM_DEBUG_KMS("Skipping Component Video\n");
  790. continue;
  791. }
  792. bios_connectors[i].connector_type =
  793. supported_devices_connector_convert[ci.sucConnectorInfo.
  794. sbfAccess.
  795. bfConnectorType];
  796. if (bios_connectors[i].connector_type ==
  797. DRM_MODE_CONNECTOR_Unknown)
  798. continue;
  799. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  800. bios_connectors[i].line_mux =
  801. ci.sucI2cId.ucAccess;
  802. /* give tv unique connector ids */
  803. if (i == ATOM_DEVICE_TV1_INDEX) {
  804. bios_connectors[i].ddc_bus.valid = false;
  805. bios_connectors[i].line_mux = 50;
  806. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  807. bios_connectors[i].ddc_bus.valid = false;
  808. bios_connectors[i].line_mux = 51;
  809. } else if (i == ATOM_DEVICE_CV_INDEX) {
  810. bios_connectors[i].ddc_bus.valid = false;
  811. bios_connectors[i].line_mux = 52;
  812. } else
  813. bios_connectors[i].ddc_bus =
  814. radeon_lookup_i2c_gpio(rdev,
  815. bios_connectors[i].line_mux);
  816. if ((crev > 1) && (frev > 1)) {
  817. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  818. switch (isb) {
  819. case 0x4:
  820. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  821. break;
  822. case 0xa:
  823. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  824. break;
  825. default:
  826. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  827. break;
  828. }
  829. } else {
  830. if (i == ATOM_DEVICE_DFP1_INDEX)
  831. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  832. else if (i == ATOM_DEVICE_DFP2_INDEX)
  833. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  834. else
  835. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  836. }
  837. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  838. * shared with a DVI port, we'll pick up the DVI connector when we
  839. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  840. */
  841. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  842. bios_connectors[i].connector_type =
  843. DRM_MODE_CONNECTOR_VGA;
  844. if (!radeon_atom_apply_quirks
  845. (dev, (1 << i), &bios_connectors[i].connector_type,
  846. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  847. &bios_connectors[i].hpd))
  848. continue;
  849. bios_connectors[i].valid = true;
  850. bios_connectors[i].devices = (1 << i);
  851. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  852. radeon_add_atom_encoder(dev,
  853. radeon_get_encoder_enum(dev,
  854. (1 << i),
  855. dac),
  856. (1 << i));
  857. else
  858. radeon_add_legacy_encoder(dev,
  859. radeon_get_encoder_enum(dev,
  860. (1 << i),
  861. dac),
  862. (1 << i));
  863. }
  864. /* combine shared connectors */
  865. for (i = 0; i < max_device; i++) {
  866. if (bios_connectors[i].valid) {
  867. for (j = 0; j < max_device; j++) {
  868. if (bios_connectors[j].valid && (i != j)) {
  869. if (bios_connectors[i].line_mux ==
  870. bios_connectors[j].line_mux) {
  871. /* make sure not to combine LVDS */
  872. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  873. bios_connectors[i].line_mux = 53;
  874. bios_connectors[i].ddc_bus.valid = false;
  875. continue;
  876. }
  877. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  878. bios_connectors[j].line_mux = 53;
  879. bios_connectors[j].ddc_bus.valid = false;
  880. continue;
  881. }
  882. /* combine analog and digital for DVI-I */
  883. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  884. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  885. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  886. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  887. bios_connectors[i].devices |=
  888. bios_connectors[j].devices;
  889. bios_connectors[i].connector_type =
  890. DRM_MODE_CONNECTOR_DVII;
  891. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  892. bios_connectors[i].hpd =
  893. bios_connectors[j].hpd;
  894. bios_connectors[j].valid = false;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. /* add the connectors */
  902. for (i = 0; i < max_device; i++) {
  903. if (bios_connectors[i].valid) {
  904. uint16_t connector_object_id =
  905. atombios_get_connector_object_id(dev,
  906. bios_connectors[i].connector_type,
  907. bios_connectors[i].devices);
  908. radeon_add_atom_connector(dev,
  909. bios_connectors[i].line_mux,
  910. bios_connectors[i].devices,
  911. bios_connectors[i].
  912. connector_type,
  913. &bios_connectors[i].ddc_bus,
  914. 0,
  915. connector_object_id,
  916. &bios_connectors[i].hpd,
  917. &router);
  918. }
  919. }
  920. radeon_link_encoder_connector(dev);
  921. kfree(bios_connectors);
  922. return true;
  923. }
  924. union firmware_info {
  925. ATOM_FIRMWARE_INFO info;
  926. ATOM_FIRMWARE_INFO_V1_2 info_12;
  927. ATOM_FIRMWARE_INFO_V1_3 info_13;
  928. ATOM_FIRMWARE_INFO_V1_4 info_14;
  929. ATOM_FIRMWARE_INFO_V2_1 info_21;
  930. };
  931. bool radeon_atom_get_clock_info(struct drm_device *dev)
  932. {
  933. struct radeon_device *rdev = dev->dev_private;
  934. struct radeon_mode_info *mode_info = &rdev->mode_info;
  935. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  936. union firmware_info *firmware_info;
  937. uint8_t frev, crev;
  938. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  939. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  940. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  941. struct radeon_pll *spll = &rdev->clock.spll;
  942. struct radeon_pll *mpll = &rdev->clock.mpll;
  943. uint16_t data_offset;
  944. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  945. &frev, &crev, &data_offset)) {
  946. firmware_info =
  947. (union firmware_info *)(mode_info->atom_context->bios +
  948. data_offset);
  949. /* pixel clocks */
  950. p1pll->reference_freq =
  951. le16_to_cpu(firmware_info->info.usReferenceClock);
  952. p1pll->reference_div = 0;
  953. if (crev < 2)
  954. p1pll->pll_out_min =
  955. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  956. else
  957. p1pll->pll_out_min =
  958. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  959. p1pll->pll_out_max =
  960. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  961. if (crev >= 4) {
  962. p1pll->lcd_pll_out_min =
  963. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  964. if (p1pll->lcd_pll_out_min == 0)
  965. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  966. p1pll->lcd_pll_out_max =
  967. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  968. if (p1pll->lcd_pll_out_max == 0)
  969. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  970. } else {
  971. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  972. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  973. }
  974. if (p1pll->pll_out_min == 0) {
  975. if (ASIC_IS_AVIVO(rdev))
  976. p1pll->pll_out_min = 64800;
  977. else
  978. p1pll->pll_out_min = 20000;
  979. } else if (p1pll->pll_out_min > 64800) {
  980. /* Limiting the pll output range is a good thing generally as
  981. * it limits the number of possible pll combinations for a given
  982. * frequency presumably to the ones that work best on each card.
  983. * However, certain duallink DVI monitors seem to like
  984. * pll combinations that would be limited by this at least on
  985. * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
  986. * family.
  987. */
  988. p1pll->pll_out_min = 64800;
  989. }
  990. p1pll->pll_in_min =
  991. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  992. p1pll->pll_in_max =
  993. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  994. *p2pll = *p1pll;
  995. /* system clock */
  996. spll->reference_freq =
  997. le16_to_cpu(firmware_info->info.usReferenceClock);
  998. spll->reference_div = 0;
  999. spll->pll_out_min =
  1000. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1001. spll->pll_out_max =
  1002. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1003. /* ??? */
  1004. if (spll->pll_out_min == 0) {
  1005. if (ASIC_IS_AVIVO(rdev))
  1006. spll->pll_out_min = 64800;
  1007. else
  1008. spll->pll_out_min = 20000;
  1009. }
  1010. spll->pll_in_min =
  1011. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1012. spll->pll_in_max =
  1013. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1014. /* memory clock */
  1015. mpll->reference_freq =
  1016. le16_to_cpu(firmware_info->info.usReferenceClock);
  1017. mpll->reference_div = 0;
  1018. mpll->pll_out_min =
  1019. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1020. mpll->pll_out_max =
  1021. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1022. /* ??? */
  1023. if (mpll->pll_out_min == 0) {
  1024. if (ASIC_IS_AVIVO(rdev))
  1025. mpll->pll_out_min = 64800;
  1026. else
  1027. mpll->pll_out_min = 20000;
  1028. }
  1029. mpll->pll_in_min =
  1030. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1031. mpll->pll_in_max =
  1032. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1033. rdev->clock.default_sclk =
  1034. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1035. rdev->clock.default_mclk =
  1036. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1037. if (ASIC_IS_DCE4(rdev)) {
  1038. rdev->clock.default_dispclk =
  1039. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1040. if (rdev->clock.default_dispclk == 0)
  1041. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1042. rdev->clock.dp_extclk =
  1043. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1044. }
  1045. *dcpll = *p1pll;
  1046. return true;
  1047. }
  1048. return false;
  1049. }
  1050. union igp_info {
  1051. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1052. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1053. };
  1054. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1055. {
  1056. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1057. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1058. union igp_info *igp_info;
  1059. u8 frev, crev;
  1060. u16 data_offset;
  1061. /* sideport is AMD only */
  1062. if (rdev->family == CHIP_RS600)
  1063. return false;
  1064. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1065. &frev, &crev, &data_offset)) {
  1066. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1067. data_offset);
  1068. switch (crev) {
  1069. case 1:
  1070. if (igp_info->info.ulBootUpMemoryClock)
  1071. return true;
  1072. break;
  1073. case 2:
  1074. if (igp_info->info_2.ulBootUpSidePortClock)
  1075. return true;
  1076. break;
  1077. default:
  1078. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1079. break;
  1080. }
  1081. }
  1082. return false;
  1083. }
  1084. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1085. struct radeon_encoder_int_tmds *tmds)
  1086. {
  1087. struct drm_device *dev = encoder->base.dev;
  1088. struct radeon_device *rdev = dev->dev_private;
  1089. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1090. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1091. uint16_t data_offset;
  1092. struct _ATOM_TMDS_INFO *tmds_info;
  1093. uint8_t frev, crev;
  1094. uint16_t maxfreq;
  1095. int i;
  1096. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1097. &frev, &crev, &data_offset)) {
  1098. tmds_info =
  1099. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1100. data_offset);
  1101. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1102. for (i = 0; i < 4; i++) {
  1103. tmds->tmds_pll[i].freq =
  1104. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1105. tmds->tmds_pll[i].value =
  1106. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1107. tmds->tmds_pll[i].value |=
  1108. (tmds_info->asMiscInfo[i].
  1109. ucPLL_VCO_Gain & 0x3f) << 6;
  1110. tmds->tmds_pll[i].value |=
  1111. (tmds_info->asMiscInfo[i].
  1112. ucPLL_DutyCycle & 0xf) << 12;
  1113. tmds->tmds_pll[i].value |=
  1114. (tmds_info->asMiscInfo[i].
  1115. ucPLL_VoltageSwing & 0xf) << 16;
  1116. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1117. tmds->tmds_pll[i].freq,
  1118. tmds->tmds_pll[i].value);
  1119. if (maxfreq == tmds->tmds_pll[i].freq) {
  1120. tmds->tmds_pll[i].freq = 0xffffffff;
  1121. break;
  1122. }
  1123. }
  1124. return true;
  1125. }
  1126. return false;
  1127. }
  1128. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1129. struct radeon_atom_ss *ss,
  1130. int id)
  1131. {
  1132. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1133. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1134. uint16_t data_offset, size;
  1135. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1136. uint8_t frev, crev;
  1137. int i, num_indices;
  1138. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1139. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1140. &frev, &crev, &data_offset)) {
  1141. ss_info =
  1142. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1143. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1144. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1145. for (i = 0; i < num_indices; i++) {
  1146. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1147. ss->percentage =
  1148. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1149. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1150. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1151. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1152. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1153. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1154. return true;
  1155. }
  1156. }
  1157. }
  1158. return false;
  1159. }
  1160. union asic_ss_info {
  1161. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1162. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1163. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1164. };
  1165. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1166. struct radeon_atom_ss *ss,
  1167. int id, u32 clock)
  1168. {
  1169. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1170. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1171. uint16_t data_offset, size;
  1172. union asic_ss_info *ss_info;
  1173. uint8_t frev, crev;
  1174. int i, num_indices;
  1175. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1176. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1177. &frev, &crev, &data_offset)) {
  1178. ss_info =
  1179. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1180. switch (frev) {
  1181. case 1:
  1182. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1183. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1184. for (i = 0; i < num_indices; i++) {
  1185. if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
  1186. (clock <= ss_info->info.asSpreadSpectrum[i].ulTargetClockRange)) {
  1187. ss->percentage =
  1188. le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1189. ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1190. ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
  1191. return true;
  1192. }
  1193. }
  1194. break;
  1195. case 2:
  1196. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1197. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1198. for (i = 0; i < num_indices; i++) {
  1199. if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
  1200. (clock <= ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange)) {
  1201. ss->percentage =
  1202. le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1203. ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1204. ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1205. return true;
  1206. }
  1207. }
  1208. break;
  1209. case 3:
  1210. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1211. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1212. for (i = 0; i < num_indices; i++) {
  1213. if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
  1214. (clock <= ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange)) {
  1215. ss->percentage =
  1216. le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
  1217. ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
  1218. ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
  1219. return true;
  1220. }
  1221. }
  1222. break;
  1223. default:
  1224. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1225. break;
  1226. }
  1227. }
  1228. return false;
  1229. }
  1230. union lvds_info {
  1231. struct _ATOM_LVDS_INFO info;
  1232. struct _ATOM_LVDS_INFO_V12 info_12;
  1233. };
  1234. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1235. radeon_encoder
  1236. *encoder)
  1237. {
  1238. struct drm_device *dev = encoder->base.dev;
  1239. struct radeon_device *rdev = dev->dev_private;
  1240. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1241. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1242. uint16_t data_offset, misc;
  1243. union lvds_info *lvds_info;
  1244. uint8_t frev, crev;
  1245. struct radeon_encoder_atom_dig *lvds = NULL;
  1246. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1247. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1248. &frev, &crev, &data_offset)) {
  1249. lvds_info =
  1250. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1251. lvds =
  1252. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1253. if (!lvds)
  1254. return NULL;
  1255. lvds->native_mode.clock =
  1256. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1257. lvds->native_mode.hdisplay =
  1258. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1259. lvds->native_mode.vdisplay =
  1260. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1261. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1262. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1263. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1264. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1265. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1266. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1267. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1268. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1269. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1270. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1271. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1272. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1273. lvds->panel_pwr_delay =
  1274. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1275. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1276. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1277. if (misc & ATOM_VSYNC_POLARITY)
  1278. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1279. if (misc & ATOM_HSYNC_POLARITY)
  1280. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1281. if (misc & ATOM_COMPOSITESYNC)
  1282. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1283. if (misc & ATOM_INTERLACE)
  1284. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1285. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1286. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1287. /* set crtc values */
  1288. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1289. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1290. encoder->native_mode = lvds->native_mode;
  1291. if (encoder_enum == 2)
  1292. lvds->linkb = true;
  1293. else
  1294. lvds->linkb = false;
  1295. }
  1296. return lvds;
  1297. }
  1298. struct radeon_encoder_primary_dac *
  1299. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1300. {
  1301. struct drm_device *dev = encoder->base.dev;
  1302. struct radeon_device *rdev = dev->dev_private;
  1303. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1304. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1305. uint16_t data_offset;
  1306. struct _COMPASSIONATE_DATA *dac_info;
  1307. uint8_t frev, crev;
  1308. uint8_t bg, dac;
  1309. struct radeon_encoder_primary_dac *p_dac = NULL;
  1310. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1311. &frev, &crev, &data_offset)) {
  1312. dac_info = (struct _COMPASSIONATE_DATA *)
  1313. (mode_info->atom_context->bios + data_offset);
  1314. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1315. if (!p_dac)
  1316. return NULL;
  1317. bg = dac_info->ucDAC1_BG_Adjustment;
  1318. dac = dac_info->ucDAC1_DAC_Adjustment;
  1319. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1320. }
  1321. return p_dac;
  1322. }
  1323. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1324. struct drm_display_mode *mode)
  1325. {
  1326. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1327. ATOM_ANALOG_TV_INFO *tv_info;
  1328. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1329. ATOM_DTD_FORMAT *dtd_timings;
  1330. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1331. u8 frev, crev;
  1332. u16 data_offset, misc;
  1333. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1334. &frev, &crev, &data_offset))
  1335. return false;
  1336. switch (crev) {
  1337. case 1:
  1338. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1339. if (index >= MAX_SUPPORTED_TV_TIMING)
  1340. return false;
  1341. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1342. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1343. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1344. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1345. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1346. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1347. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1348. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1349. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1350. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1351. mode->flags = 0;
  1352. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1353. if (misc & ATOM_VSYNC_POLARITY)
  1354. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1355. if (misc & ATOM_HSYNC_POLARITY)
  1356. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1357. if (misc & ATOM_COMPOSITESYNC)
  1358. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1359. if (misc & ATOM_INTERLACE)
  1360. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1361. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1362. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1363. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1364. if (index == 1) {
  1365. /* PAL timings appear to have wrong values for totals */
  1366. mode->crtc_htotal -= 1;
  1367. mode->crtc_vtotal -= 1;
  1368. }
  1369. break;
  1370. case 2:
  1371. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1372. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1373. return false;
  1374. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1375. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1376. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1377. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1378. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1379. le16_to_cpu(dtd_timings->usHSyncOffset);
  1380. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1381. le16_to_cpu(dtd_timings->usHSyncWidth);
  1382. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1383. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1384. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1385. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1386. le16_to_cpu(dtd_timings->usVSyncOffset);
  1387. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1388. le16_to_cpu(dtd_timings->usVSyncWidth);
  1389. mode->flags = 0;
  1390. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1391. if (misc & ATOM_VSYNC_POLARITY)
  1392. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1393. if (misc & ATOM_HSYNC_POLARITY)
  1394. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1395. if (misc & ATOM_COMPOSITESYNC)
  1396. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1397. if (misc & ATOM_INTERLACE)
  1398. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1399. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1400. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1401. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1402. break;
  1403. }
  1404. return true;
  1405. }
  1406. enum radeon_tv_std
  1407. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1408. {
  1409. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1410. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1411. uint16_t data_offset;
  1412. uint8_t frev, crev;
  1413. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1414. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1415. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1416. &frev, &crev, &data_offset)) {
  1417. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1418. (mode_info->atom_context->bios + data_offset);
  1419. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1420. case ATOM_TV_NTSC:
  1421. tv_std = TV_STD_NTSC;
  1422. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1423. break;
  1424. case ATOM_TV_NTSCJ:
  1425. tv_std = TV_STD_NTSC_J;
  1426. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1427. break;
  1428. case ATOM_TV_PAL:
  1429. tv_std = TV_STD_PAL;
  1430. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1431. break;
  1432. case ATOM_TV_PALM:
  1433. tv_std = TV_STD_PAL_M;
  1434. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1435. break;
  1436. case ATOM_TV_PALN:
  1437. tv_std = TV_STD_PAL_N;
  1438. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1439. break;
  1440. case ATOM_TV_PALCN:
  1441. tv_std = TV_STD_PAL_CN;
  1442. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1443. break;
  1444. case ATOM_TV_PAL60:
  1445. tv_std = TV_STD_PAL_60;
  1446. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1447. break;
  1448. case ATOM_TV_SECAM:
  1449. tv_std = TV_STD_SECAM;
  1450. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1451. break;
  1452. default:
  1453. tv_std = TV_STD_NTSC;
  1454. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1455. break;
  1456. }
  1457. }
  1458. return tv_std;
  1459. }
  1460. struct radeon_encoder_tv_dac *
  1461. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1462. {
  1463. struct drm_device *dev = encoder->base.dev;
  1464. struct radeon_device *rdev = dev->dev_private;
  1465. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1466. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1467. uint16_t data_offset;
  1468. struct _COMPASSIONATE_DATA *dac_info;
  1469. uint8_t frev, crev;
  1470. uint8_t bg, dac;
  1471. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1472. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1473. &frev, &crev, &data_offset)) {
  1474. dac_info = (struct _COMPASSIONATE_DATA *)
  1475. (mode_info->atom_context->bios + data_offset);
  1476. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1477. if (!tv_dac)
  1478. return NULL;
  1479. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1480. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1481. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1482. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1483. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1484. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1485. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1486. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1487. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1488. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1489. }
  1490. return tv_dac;
  1491. }
  1492. static const char *thermal_controller_names[] = {
  1493. "NONE",
  1494. "lm63",
  1495. "adm1032",
  1496. "adm1030",
  1497. "max6649",
  1498. "lm64",
  1499. "f75375",
  1500. "asc7xxx",
  1501. };
  1502. static const char *pp_lib_thermal_controller_names[] = {
  1503. "NONE",
  1504. "lm63",
  1505. "adm1032",
  1506. "adm1030",
  1507. "max6649",
  1508. "lm64",
  1509. "f75375",
  1510. "RV6xx",
  1511. "RV770",
  1512. "adt7473",
  1513. "External GPIO",
  1514. "Evergreen",
  1515. "adt7473 with internal",
  1516. };
  1517. union power_info {
  1518. struct _ATOM_POWERPLAY_INFO info;
  1519. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1520. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1521. struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
  1522. };
  1523. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  1524. {
  1525. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1526. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1527. u16 data_offset;
  1528. u8 frev, crev;
  1529. u32 misc, misc2 = 0, sclk, mclk;
  1530. union power_info *power_info;
  1531. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1532. struct _ATOM_PPLIB_STATE *power_state;
  1533. int num_modes = 0, i, j;
  1534. int state_index = 0, mode_index = 0;
  1535. struct radeon_i2c_bus_rec i2c_bus;
  1536. rdev->pm.default_power_state_index = -1;
  1537. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1538. &frev, &crev, &data_offset)) {
  1539. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1540. if (frev < 4) {
  1541. /* add the i2c bus for thermal/fan chip */
  1542. if (power_info->info.ucOverdriveThermalController > 0) {
  1543. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1544. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1545. power_info->info.ucOverdriveControllerAddress >> 1);
  1546. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1547. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1548. if (rdev->pm.i2c_bus) {
  1549. struct i2c_board_info info = { };
  1550. const char *name = thermal_controller_names[power_info->info.
  1551. ucOverdriveThermalController];
  1552. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1553. strlcpy(info.type, name, sizeof(info.type));
  1554. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1555. }
  1556. }
  1557. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1558. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1559. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1560. /* last mode is usually default, array is low to high */
  1561. for (i = 0; i < num_modes; i++) {
  1562. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1563. switch (frev) {
  1564. case 1:
  1565. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1566. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1567. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1568. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1569. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1570. /* skip invalid modes */
  1571. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1572. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1573. continue;
  1574. rdev->pm.power_state[state_index].pcie_lanes =
  1575. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1576. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1577. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1578. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1579. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1580. VOLTAGE_GPIO;
  1581. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1582. radeon_lookup_gpio(rdev,
  1583. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1584. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1585. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1586. true;
  1587. else
  1588. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1589. false;
  1590. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1591. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1592. VOLTAGE_VDDC;
  1593. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1594. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1595. }
  1596. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1597. rdev->pm.power_state[state_index].misc = misc;
  1598. /* order matters! */
  1599. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1600. rdev->pm.power_state[state_index].type =
  1601. POWER_STATE_TYPE_POWERSAVE;
  1602. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1603. rdev->pm.power_state[state_index].type =
  1604. POWER_STATE_TYPE_BATTERY;
  1605. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1606. rdev->pm.power_state[state_index].type =
  1607. POWER_STATE_TYPE_BATTERY;
  1608. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1609. rdev->pm.power_state[state_index].type =
  1610. POWER_STATE_TYPE_BALANCED;
  1611. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1612. rdev->pm.power_state[state_index].type =
  1613. POWER_STATE_TYPE_PERFORMANCE;
  1614. rdev->pm.power_state[state_index].flags &=
  1615. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1616. }
  1617. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1618. rdev->pm.power_state[state_index].type =
  1619. POWER_STATE_TYPE_DEFAULT;
  1620. rdev->pm.default_power_state_index = state_index;
  1621. rdev->pm.power_state[state_index].default_clock_mode =
  1622. &rdev->pm.power_state[state_index].clock_info[0];
  1623. rdev->pm.power_state[state_index].flags &=
  1624. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1625. } else if (state_index == 0) {
  1626. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1627. RADEON_PM_MODE_NO_DISPLAY;
  1628. }
  1629. state_index++;
  1630. break;
  1631. case 2:
  1632. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1633. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1634. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1635. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1636. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1637. /* skip invalid modes */
  1638. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1639. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1640. continue;
  1641. rdev->pm.power_state[state_index].pcie_lanes =
  1642. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1643. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1644. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1645. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1646. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1647. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1648. VOLTAGE_GPIO;
  1649. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1650. radeon_lookup_gpio(rdev,
  1651. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1652. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1653. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1654. true;
  1655. else
  1656. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1657. false;
  1658. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1659. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1660. VOLTAGE_VDDC;
  1661. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1662. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1663. }
  1664. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1665. rdev->pm.power_state[state_index].misc = misc;
  1666. rdev->pm.power_state[state_index].misc2 = misc2;
  1667. /* order matters! */
  1668. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1669. rdev->pm.power_state[state_index].type =
  1670. POWER_STATE_TYPE_POWERSAVE;
  1671. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1672. rdev->pm.power_state[state_index].type =
  1673. POWER_STATE_TYPE_BATTERY;
  1674. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1675. rdev->pm.power_state[state_index].type =
  1676. POWER_STATE_TYPE_BATTERY;
  1677. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1678. rdev->pm.power_state[state_index].type =
  1679. POWER_STATE_TYPE_BALANCED;
  1680. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1681. rdev->pm.power_state[state_index].type =
  1682. POWER_STATE_TYPE_PERFORMANCE;
  1683. rdev->pm.power_state[state_index].flags &=
  1684. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1685. }
  1686. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1687. rdev->pm.power_state[state_index].type =
  1688. POWER_STATE_TYPE_BALANCED;
  1689. if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
  1690. rdev->pm.power_state[state_index].flags &=
  1691. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1692. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1693. rdev->pm.power_state[state_index].type =
  1694. POWER_STATE_TYPE_DEFAULT;
  1695. rdev->pm.default_power_state_index = state_index;
  1696. rdev->pm.power_state[state_index].default_clock_mode =
  1697. &rdev->pm.power_state[state_index].clock_info[0];
  1698. rdev->pm.power_state[state_index].flags &=
  1699. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1700. } else if (state_index == 0) {
  1701. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1702. RADEON_PM_MODE_NO_DISPLAY;
  1703. }
  1704. state_index++;
  1705. break;
  1706. case 3:
  1707. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1708. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1709. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1710. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1711. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1712. /* skip invalid modes */
  1713. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1714. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1715. continue;
  1716. rdev->pm.power_state[state_index].pcie_lanes =
  1717. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1718. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1719. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1720. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1721. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1722. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1723. VOLTAGE_GPIO;
  1724. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1725. radeon_lookup_gpio(rdev,
  1726. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1727. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1728. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1729. true;
  1730. else
  1731. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1732. false;
  1733. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1734. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1735. VOLTAGE_VDDC;
  1736. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1737. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1738. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1739. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1740. true;
  1741. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1742. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1743. }
  1744. }
  1745. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1746. rdev->pm.power_state[state_index].misc = misc;
  1747. rdev->pm.power_state[state_index].misc2 = misc2;
  1748. /* order matters! */
  1749. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1750. rdev->pm.power_state[state_index].type =
  1751. POWER_STATE_TYPE_POWERSAVE;
  1752. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1753. rdev->pm.power_state[state_index].type =
  1754. POWER_STATE_TYPE_BATTERY;
  1755. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1756. rdev->pm.power_state[state_index].type =
  1757. POWER_STATE_TYPE_BATTERY;
  1758. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1759. rdev->pm.power_state[state_index].type =
  1760. POWER_STATE_TYPE_BALANCED;
  1761. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1762. rdev->pm.power_state[state_index].type =
  1763. POWER_STATE_TYPE_PERFORMANCE;
  1764. rdev->pm.power_state[state_index].flags &=
  1765. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1766. }
  1767. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1768. rdev->pm.power_state[state_index].type =
  1769. POWER_STATE_TYPE_BALANCED;
  1770. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1771. rdev->pm.power_state[state_index].type =
  1772. POWER_STATE_TYPE_DEFAULT;
  1773. rdev->pm.default_power_state_index = state_index;
  1774. rdev->pm.power_state[state_index].default_clock_mode =
  1775. &rdev->pm.power_state[state_index].clock_info[0];
  1776. } else if (state_index == 0) {
  1777. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1778. RADEON_PM_MODE_NO_DISPLAY;
  1779. }
  1780. state_index++;
  1781. break;
  1782. }
  1783. }
  1784. /* last mode is usually default */
  1785. if (rdev->pm.default_power_state_index == -1) {
  1786. rdev->pm.power_state[state_index - 1].type =
  1787. POWER_STATE_TYPE_DEFAULT;
  1788. rdev->pm.default_power_state_index = state_index - 1;
  1789. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1790. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1791. rdev->pm.power_state[state_index].flags &=
  1792. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1793. rdev->pm.power_state[state_index].misc = 0;
  1794. rdev->pm.power_state[state_index].misc2 = 0;
  1795. }
  1796. } else {
  1797. int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  1798. uint8_t fw_frev, fw_crev;
  1799. uint16_t fw_data_offset, vddc = 0;
  1800. union firmware_info *firmware_info;
  1801. ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
  1802. if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
  1803. &fw_frev, &fw_crev, &fw_data_offset)) {
  1804. firmware_info =
  1805. (union firmware_info *)(mode_info->atom_context->bios +
  1806. fw_data_offset);
  1807. vddc = firmware_info->info_14.usBootUpVDDCVoltage;
  1808. }
  1809. /* add the i2c bus for thermal/fan chip */
  1810. if (controller->ucType > 0) {
  1811. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1812. DRM_INFO("Internal thermal controller %s fan control\n",
  1813. (controller->ucFanParameters &
  1814. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1815. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1816. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1817. DRM_INFO("Internal thermal controller %s fan control\n",
  1818. (controller->ucFanParameters &
  1819. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1820. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1821. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  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_EVERGREEN;
  1826. } else if ((controller->ucType ==
  1827. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1828. (controller->ucType ==
  1829. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
  1830. DRM_INFO("Special thermal controller config\n");
  1831. } else {
  1832. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1833. pp_lib_thermal_controller_names[controller->ucType],
  1834. controller->ucI2cAddress >> 1,
  1835. (controller->ucFanParameters &
  1836. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1837. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1838. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1839. if (rdev->pm.i2c_bus) {
  1840. struct i2c_board_info info = { };
  1841. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  1842. info.addr = controller->ucI2cAddress >> 1;
  1843. strlcpy(info.type, name, sizeof(info.type));
  1844. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1845. }
  1846. }
  1847. }
  1848. /* first mode is usually default, followed by low to high */
  1849. for (i = 0; i < power_info->info_4.ucNumStates; i++) {
  1850. mode_index = 0;
  1851. power_state = (struct _ATOM_PPLIB_STATE *)
  1852. (mode_info->atom_context->bios +
  1853. data_offset +
  1854. le16_to_cpu(power_info->info_4.usStateArrayOffset) +
  1855. i * power_info->info_4.ucStateEntrySize);
  1856. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1857. (mode_info->atom_context->bios +
  1858. data_offset +
  1859. le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
  1860. (power_state->ucNonClockStateIndex *
  1861. power_info->info_4.ucNonClockSize));
  1862. for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
  1863. if (rdev->flags & RADEON_IS_IGP) {
  1864. struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
  1865. (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
  1866. (mode_info->atom_context->bios +
  1867. data_offset +
  1868. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1869. (power_state->ucClockStateIndices[j] *
  1870. power_info->info_4.ucClockInfoSize));
  1871. sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
  1872. sclk |= clock_info->ucLowEngineClockHigh << 16;
  1873. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1874. /* skip invalid modes */
  1875. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  1876. continue;
  1877. /* voltage works differently on IGPs */
  1878. mode_index++;
  1879. } else if (ASIC_IS_DCE4(rdev)) {
  1880. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
  1881. (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
  1882. (mode_info->atom_context->bios +
  1883. data_offset +
  1884. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1885. (power_state->ucClockStateIndices[j] *
  1886. power_info->info_4.ucClockInfoSize));
  1887. sclk = le16_to_cpu(clock_info->usEngineClockLow);
  1888. sclk |= clock_info->ucEngineClockHigh << 16;
  1889. mclk = le16_to_cpu(clock_info->usMemoryClockLow);
  1890. mclk |= clock_info->ucMemoryClockHigh << 16;
  1891. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1892. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1893. /* skip invalid modes */
  1894. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  1895. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  1896. continue;
  1897. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1898. VOLTAGE_SW;
  1899. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1900. clock_info->usVDDC;
  1901. /* XXX usVDDCI */
  1902. mode_index++;
  1903. } else {
  1904. struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
  1905. (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
  1906. (mode_info->atom_context->bios +
  1907. data_offset +
  1908. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1909. (power_state->ucClockStateIndices[j] *
  1910. power_info->info_4.ucClockInfoSize));
  1911. sclk = le16_to_cpu(clock_info->usEngineClockLow);
  1912. sclk |= clock_info->ucEngineClockHigh << 16;
  1913. mclk = le16_to_cpu(clock_info->usMemoryClockLow);
  1914. mclk |= clock_info->ucMemoryClockHigh << 16;
  1915. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1916. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1917. /* skip invalid modes */
  1918. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  1919. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  1920. continue;
  1921. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1922. VOLTAGE_SW;
  1923. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1924. clock_info->usVDDC;
  1925. mode_index++;
  1926. }
  1927. }
  1928. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  1929. if (mode_index) {
  1930. misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1931. misc2 = le16_to_cpu(non_clock_info->usClassification);
  1932. rdev->pm.power_state[state_index].misc = misc;
  1933. rdev->pm.power_state[state_index].misc2 = misc2;
  1934. rdev->pm.power_state[state_index].pcie_lanes =
  1935. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  1936. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  1937. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  1938. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  1939. rdev->pm.power_state[state_index].type =
  1940. POWER_STATE_TYPE_BATTERY;
  1941. break;
  1942. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  1943. rdev->pm.power_state[state_index].type =
  1944. POWER_STATE_TYPE_BALANCED;
  1945. break;
  1946. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  1947. rdev->pm.power_state[state_index].type =
  1948. POWER_STATE_TYPE_PERFORMANCE;
  1949. break;
  1950. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  1951. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  1952. rdev->pm.power_state[state_index].type =
  1953. POWER_STATE_TYPE_PERFORMANCE;
  1954. break;
  1955. }
  1956. rdev->pm.power_state[state_index].flags = 0;
  1957. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  1958. rdev->pm.power_state[state_index].flags |=
  1959. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1960. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1961. rdev->pm.power_state[state_index].type =
  1962. POWER_STATE_TYPE_DEFAULT;
  1963. rdev->pm.default_power_state_index = state_index;
  1964. rdev->pm.power_state[state_index].default_clock_mode =
  1965. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  1966. /* patch the table values with the default slck/mclk from firmware info */
  1967. for (j = 0; j < mode_index; j++) {
  1968. rdev->pm.power_state[state_index].clock_info[j].mclk =
  1969. rdev->clock.default_mclk;
  1970. rdev->pm.power_state[state_index].clock_info[j].sclk =
  1971. rdev->clock.default_sclk;
  1972. if (vddc)
  1973. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  1974. vddc;
  1975. }
  1976. }
  1977. state_index++;
  1978. }
  1979. }
  1980. /* if multiple clock modes, mark the lowest as no display */
  1981. for (i = 0; i < state_index; i++) {
  1982. if (rdev->pm.power_state[i].num_clock_modes > 1)
  1983. rdev->pm.power_state[i].clock_info[0].flags |=
  1984. RADEON_PM_MODE_NO_DISPLAY;
  1985. }
  1986. /* first mode is usually default */
  1987. if (rdev->pm.default_power_state_index == -1) {
  1988. rdev->pm.power_state[0].type =
  1989. POWER_STATE_TYPE_DEFAULT;
  1990. rdev->pm.default_power_state_index = 0;
  1991. rdev->pm.power_state[0].default_clock_mode =
  1992. &rdev->pm.power_state[0].clock_info[0];
  1993. }
  1994. }
  1995. } else {
  1996. /* add the default mode */
  1997. rdev->pm.power_state[state_index].type =
  1998. POWER_STATE_TYPE_DEFAULT;
  1999. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2000. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2001. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2002. rdev->pm.power_state[state_index].default_clock_mode =
  2003. &rdev->pm.power_state[state_index].clock_info[0];
  2004. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2005. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2006. rdev->pm.default_power_state_index = state_index;
  2007. rdev->pm.power_state[state_index].flags = 0;
  2008. state_index++;
  2009. }
  2010. rdev->pm.num_power_states = state_index;
  2011. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2012. rdev->pm.current_clock_mode_index = 0;
  2013. rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2014. }
  2015. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2016. {
  2017. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2018. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2019. args.ucEnable = enable;
  2020. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2021. }
  2022. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2023. {
  2024. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2025. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2026. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2027. return args.ulReturnEngineClock;
  2028. }
  2029. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2030. {
  2031. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2032. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2033. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2034. return args.ulReturnMemoryClock;
  2035. }
  2036. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2037. uint32_t eng_clock)
  2038. {
  2039. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2040. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2041. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  2042. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2043. }
  2044. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2045. uint32_t mem_clock)
  2046. {
  2047. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2048. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2049. if (rdev->flags & RADEON_IS_IGP)
  2050. return;
  2051. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  2052. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2053. }
  2054. union set_voltage {
  2055. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2056. struct _SET_VOLTAGE_PARAMETERS v1;
  2057. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2058. };
  2059. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
  2060. {
  2061. union set_voltage args;
  2062. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2063. u8 frev, crev, volt_index = level;
  2064. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2065. return;
  2066. switch (crev) {
  2067. case 1:
  2068. args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2069. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2070. args.v1.ucVoltageIndex = volt_index;
  2071. break;
  2072. case 2:
  2073. args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  2074. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2075. args.v2.usVoltageLevel = cpu_to_le16(level);
  2076. break;
  2077. default:
  2078. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2079. return;
  2080. }
  2081. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2082. }
  2083. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2084. {
  2085. struct radeon_device *rdev = dev->dev_private;
  2086. uint32_t bios_2_scratch, bios_6_scratch;
  2087. if (rdev->family >= CHIP_R600) {
  2088. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2089. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2090. } else {
  2091. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2092. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2093. }
  2094. /* let the bios control the backlight */
  2095. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2096. /* tell the bios not to handle mode switching */
  2097. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  2098. if (rdev->family >= CHIP_R600) {
  2099. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2100. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2101. } else {
  2102. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2103. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2104. }
  2105. }
  2106. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2107. {
  2108. uint32_t scratch_reg;
  2109. int i;
  2110. if (rdev->family >= CHIP_R600)
  2111. scratch_reg = R600_BIOS_0_SCRATCH;
  2112. else
  2113. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2114. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2115. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2116. }
  2117. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2118. {
  2119. uint32_t scratch_reg;
  2120. int i;
  2121. if (rdev->family >= CHIP_R600)
  2122. scratch_reg = R600_BIOS_0_SCRATCH;
  2123. else
  2124. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2125. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2126. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2127. }
  2128. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2129. {
  2130. struct drm_device *dev = encoder->dev;
  2131. struct radeon_device *rdev = dev->dev_private;
  2132. uint32_t bios_6_scratch;
  2133. if (rdev->family >= CHIP_R600)
  2134. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2135. else
  2136. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2137. if (lock)
  2138. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2139. else
  2140. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2141. if (rdev->family >= CHIP_R600)
  2142. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2143. else
  2144. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2145. }
  2146. /* at some point we may want to break this out into individual functions */
  2147. void
  2148. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2149. struct drm_encoder *encoder,
  2150. bool connected)
  2151. {
  2152. struct drm_device *dev = connector->dev;
  2153. struct radeon_device *rdev = dev->dev_private;
  2154. struct radeon_connector *radeon_connector =
  2155. to_radeon_connector(connector);
  2156. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2157. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2158. if (rdev->family >= CHIP_R600) {
  2159. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2160. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2161. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2162. } else {
  2163. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2164. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2165. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2166. }
  2167. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2168. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2169. if (connected) {
  2170. DRM_DEBUG_KMS("TV1 connected\n");
  2171. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2172. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2173. } else {
  2174. DRM_DEBUG_KMS("TV1 disconnected\n");
  2175. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2176. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2177. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2178. }
  2179. }
  2180. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2181. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2182. if (connected) {
  2183. DRM_DEBUG_KMS("CV connected\n");
  2184. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2185. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2186. } else {
  2187. DRM_DEBUG_KMS("CV disconnected\n");
  2188. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2189. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2190. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2191. }
  2192. }
  2193. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2194. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2195. if (connected) {
  2196. DRM_DEBUG_KMS("LCD1 connected\n");
  2197. bios_0_scratch |= ATOM_S0_LCD1;
  2198. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2199. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2200. } else {
  2201. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2202. bios_0_scratch &= ~ATOM_S0_LCD1;
  2203. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2204. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2205. }
  2206. }
  2207. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2208. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2209. if (connected) {
  2210. DRM_DEBUG_KMS("CRT1 connected\n");
  2211. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2212. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2213. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2214. } else {
  2215. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2216. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2217. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2218. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2219. }
  2220. }
  2221. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2222. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2223. if (connected) {
  2224. DRM_DEBUG_KMS("CRT2 connected\n");
  2225. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2226. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2227. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2228. } else {
  2229. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2230. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2231. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2232. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2233. }
  2234. }
  2235. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2236. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2237. if (connected) {
  2238. DRM_DEBUG_KMS("DFP1 connected\n");
  2239. bios_0_scratch |= ATOM_S0_DFP1;
  2240. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2241. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2242. } else {
  2243. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2244. bios_0_scratch &= ~ATOM_S0_DFP1;
  2245. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2246. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2247. }
  2248. }
  2249. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2250. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2251. if (connected) {
  2252. DRM_DEBUG_KMS("DFP2 connected\n");
  2253. bios_0_scratch |= ATOM_S0_DFP2;
  2254. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2255. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2256. } else {
  2257. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2258. bios_0_scratch &= ~ATOM_S0_DFP2;
  2259. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2260. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2261. }
  2262. }
  2263. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2264. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2265. if (connected) {
  2266. DRM_DEBUG_KMS("DFP3 connected\n");
  2267. bios_0_scratch |= ATOM_S0_DFP3;
  2268. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2269. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2270. } else {
  2271. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2272. bios_0_scratch &= ~ATOM_S0_DFP3;
  2273. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2274. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2275. }
  2276. }
  2277. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2278. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2279. if (connected) {
  2280. DRM_DEBUG_KMS("DFP4 connected\n");
  2281. bios_0_scratch |= ATOM_S0_DFP4;
  2282. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2283. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2284. } else {
  2285. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2286. bios_0_scratch &= ~ATOM_S0_DFP4;
  2287. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2288. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2289. }
  2290. }
  2291. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2292. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2293. if (connected) {
  2294. DRM_DEBUG_KMS("DFP5 connected\n");
  2295. bios_0_scratch |= ATOM_S0_DFP5;
  2296. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2297. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2298. } else {
  2299. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2300. bios_0_scratch &= ~ATOM_S0_DFP5;
  2301. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2302. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2303. }
  2304. }
  2305. if (rdev->family >= CHIP_R600) {
  2306. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2307. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2308. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2309. } else {
  2310. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2311. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2312. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2313. }
  2314. }
  2315. void
  2316. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2317. {
  2318. struct drm_device *dev = encoder->dev;
  2319. struct radeon_device *rdev = dev->dev_private;
  2320. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2321. uint32_t bios_3_scratch;
  2322. if (rdev->family >= CHIP_R600)
  2323. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2324. else
  2325. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2326. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2327. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2328. bios_3_scratch |= (crtc << 18);
  2329. }
  2330. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2331. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2332. bios_3_scratch |= (crtc << 24);
  2333. }
  2334. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2335. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2336. bios_3_scratch |= (crtc << 16);
  2337. }
  2338. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2339. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2340. bios_3_scratch |= (crtc << 20);
  2341. }
  2342. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2343. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2344. bios_3_scratch |= (crtc << 17);
  2345. }
  2346. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2347. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2348. bios_3_scratch |= (crtc << 19);
  2349. }
  2350. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2351. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2352. bios_3_scratch |= (crtc << 23);
  2353. }
  2354. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2355. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2356. bios_3_scratch |= (crtc << 25);
  2357. }
  2358. if (rdev->family >= CHIP_R600)
  2359. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2360. else
  2361. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2362. }
  2363. void
  2364. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2365. {
  2366. struct drm_device *dev = encoder->dev;
  2367. struct radeon_device *rdev = dev->dev_private;
  2368. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2369. uint32_t bios_2_scratch;
  2370. if (rdev->family >= CHIP_R600)
  2371. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2372. else
  2373. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2374. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2375. if (on)
  2376. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2377. else
  2378. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2379. }
  2380. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2381. if (on)
  2382. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2383. else
  2384. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2385. }
  2386. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2387. if (on)
  2388. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2389. else
  2390. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2391. }
  2392. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2393. if (on)
  2394. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2395. else
  2396. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2397. }
  2398. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2399. if (on)
  2400. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2401. else
  2402. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2403. }
  2404. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2405. if (on)
  2406. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2407. else
  2408. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2409. }
  2410. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2411. if (on)
  2412. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2413. else
  2414. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2415. }
  2416. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2417. if (on)
  2418. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2419. else
  2420. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2421. }
  2422. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2423. if (on)
  2424. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2425. else
  2426. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2427. }
  2428. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2429. if (on)
  2430. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2431. else
  2432. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2433. }
  2434. if (rdev->family >= CHIP_R600)
  2435. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2436. else
  2437. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2438. }