radeon_atombios.c 84 KB

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