radeon_atombios.c 72 KB

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