radeon_atombios.c 77 KB

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