radeon_atombios.c 74 KB

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