radeon_atombios.c 80 KB

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