radeon_atombios.c 85 KB

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