radeon_atombios.c 71 KB

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