radeon_atombios.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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. /* from radeon_legacy_encoder.c */
  49. extern void
  50. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
  51. uint32_t supported_device);
  52. union atom_supported_devices {
  53. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  54. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  55. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  56. };
  57. static inline struct radeon_i2c_bus_rec radeon_lookup_gpio(struct drm_device
  58. *dev, uint8_t id)
  59. {
  60. struct radeon_device *rdev = dev->dev_private;
  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. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  68. i2c.valid = false;
  69. atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
  70. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  71. gpio = i2c_info->asGPIO_Info[id];
  72. i2c.mask_clk_reg = le16_to_cpu(gpio.usClkMaskRegisterIndex) * 4;
  73. i2c.mask_data_reg = le16_to_cpu(gpio.usDataMaskRegisterIndex) * 4;
  74. i2c.en_clk_reg = le16_to_cpu(gpio.usClkEnRegisterIndex) * 4;
  75. i2c.en_data_reg = le16_to_cpu(gpio.usDataEnRegisterIndex) * 4;
  76. i2c.y_clk_reg = le16_to_cpu(gpio.usClkY_RegisterIndex) * 4;
  77. i2c.y_data_reg = le16_to_cpu(gpio.usDataY_RegisterIndex) * 4;
  78. i2c.a_clk_reg = le16_to_cpu(gpio.usClkA_RegisterIndex) * 4;
  79. i2c.a_data_reg = le16_to_cpu(gpio.usDataA_RegisterIndex) * 4;
  80. i2c.mask_clk_mask = (1 << gpio.ucClkMaskShift);
  81. i2c.mask_data_mask = (1 << gpio.ucDataMaskShift);
  82. i2c.en_clk_mask = (1 << gpio.ucClkEnShift);
  83. i2c.en_data_mask = (1 << gpio.ucDataEnShift);
  84. i2c.y_clk_mask = (1 << gpio.ucClkY_Shift);
  85. i2c.y_data_mask = (1 << gpio.ucDataY_Shift);
  86. i2c.a_clk_mask = (1 << gpio.ucClkA_Shift);
  87. i2c.a_data_mask = (1 << gpio.ucDataA_Shift);
  88. i2c.valid = true;
  89. return i2c;
  90. }
  91. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  92. uint32_t supported_device,
  93. int *connector_type,
  94. struct radeon_i2c_bus_rec *i2c_bus,
  95. uint16_t *line_mux)
  96. {
  97. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  98. if ((dev->pdev->device == 0x791e) &&
  99. (dev->pdev->subsystem_vendor == 0x1043) &&
  100. (dev->pdev->subsystem_device == 0x826d)) {
  101. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  102. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  103. *connector_type = DRM_MODE_CONNECTOR_DVID;
  104. }
  105. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  106. if ((dev->pdev->device == 0x7941) &&
  107. (dev->pdev->subsystem_vendor == 0x147b) &&
  108. (dev->pdev->subsystem_device == 0x2412)) {
  109. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  110. return false;
  111. }
  112. /* Falcon NW laptop lists vga ddc line for LVDS */
  113. if ((dev->pdev->device == 0x5653) &&
  114. (dev->pdev->subsystem_vendor == 0x1462) &&
  115. (dev->pdev->subsystem_device == 0x0291)) {
  116. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  117. i2c_bus->valid = false;
  118. *line_mux = 53;
  119. }
  120. }
  121. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  122. if ((dev->pdev->device == 0x7146) &&
  123. (dev->pdev->subsystem_vendor == 0x17af) &&
  124. (dev->pdev->subsystem_device == 0x2058)) {
  125. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  126. return false;
  127. }
  128. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  129. if ((dev->pdev->device == 0x7142) &&
  130. (dev->pdev->subsystem_vendor == 0x1458) &&
  131. (dev->pdev->subsystem_device == 0x2134)) {
  132. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  133. return false;
  134. }
  135. /* Funky macbooks */
  136. if ((dev->pdev->device == 0x71C5) &&
  137. (dev->pdev->subsystem_vendor == 0x106b) &&
  138. (dev->pdev->subsystem_device == 0x0080)) {
  139. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  140. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  141. return false;
  142. }
  143. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  144. if ((dev->pdev->device == 0x9598) &&
  145. (dev->pdev->subsystem_vendor == 0x1043) &&
  146. (dev->pdev->subsystem_device == 0x01da)) {
  147. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  148. *connector_type = DRM_MODE_CONNECTOR_DVII;
  149. }
  150. }
  151. /* ASUS HD 3450 board lists the DVI port as HDMI */
  152. if ((dev->pdev->device == 0x95C5) &&
  153. (dev->pdev->subsystem_vendor == 0x1043) &&
  154. (dev->pdev->subsystem_device == 0x01e2)) {
  155. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  156. *connector_type = DRM_MODE_CONNECTOR_DVII;
  157. }
  158. }
  159. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  160. * HDMI + VGA reporting as HDMI
  161. */
  162. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  163. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  164. *connector_type = DRM_MODE_CONNECTOR_VGA;
  165. *line_mux = 0;
  166. }
  167. }
  168. /* Acer laptop reports DVI-D as DVI-I */
  169. if ((dev->pdev->device == 0x95c4) &&
  170. (dev->pdev->subsystem_vendor == 0x1025) &&
  171. (dev->pdev->subsystem_device == 0x013c)) {
  172. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  173. (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
  174. *connector_type = DRM_MODE_CONNECTOR_DVID;
  175. }
  176. return true;
  177. }
  178. const int supported_devices_connector_convert[] = {
  179. DRM_MODE_CONNECTOR_Unknown,
  180. DRM_MODE_CONNECTOR_VGA,
  181. DRM_MODE_CONNECTOR_DVII,
  182. DRM_MODE_CONNECTOR_DVID,
  183. DRM_MODE_CONNECTOR_DVIA,
  184. DRM_MODE_CONNECTOR_SVIDEO,
  185. DRM_MODE_CONNECTOR_Composite,
  186. DRM_MODE_CONNECTOR_LVDS,
  187. DRM_MODE_CONNECTOR_Unknown,
  188. DRM_MODE_CONNECTOR_Unknown,
  189. DRM_MODE_CONNECTOR_HDMIA,
  190. DRM_MODE_CONNECTOR_HDMIB,
  191. DRM_MODE_CONNECTOR_Unknown,
  192. DRM_MODE_CONNECTOR_Unknown,
  193. DRM_MODE_CONNECTOR_9PinDIN,
  194. DRM_MODE_CONNECTOR_DisplayPort
  195. };
  196. const uint16_t supported_devices_connector_object_id_convert[] = {
  197. CONNECTOR_OBJECT_ID_NONE,
  198. CONNECTOR_OBJECT_ID_VGA,
  199. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  200. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  201. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  202. CONNECTOR_OBJECT_ID_COMPOSITE,
  203. CONNECTOR_OBJECT_ID_SVIDEO,
  204. CONNECTOR_OBJECT_ID_LVDS,
  205. CONNECTOR_OBJECT_ID_9PIN_DIN,
  206. CONNECTOR_OBJECT_ID_9PIN_DIN,
  207. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  208. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  209. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  210. CONNECTOR_OBJECT_ID_SVIDEO
  211. };
  212. const int object_connector_convert[] = {
  213. DRM_MODE_CONNECTOR_Unknown,
  214. DRM_MODE_CONNECTOR_DVII,
  215. DRM_MODE_CONNECTOR_DVII,
  216. DRM_MODE_CONNECTOR_DVID,
  217. DRM_MODE_CONNECTOR_DVID,
  218. DRM_MODE_CONNECTOR_VGA,
  219. DRM_MODE_CONNECTOR_Composite,
  220. DRM_MODE_CONNECTOR_SVIDEO,
  221. DRM_MODE_CONNECTOR_Unknown,
  222. DRM_MODE_CONNECTOR_Unknown,
  223. DRM_MODE_CONNECTOR_9PinDIN,
  224. DRM_MODE_CONNECTOR_Unknown,
  225. DRM_MODE_CONNECTOR_HDMIA,
  226. DRM_MODE_CONNECTOR_HDMIB,
  227. DRM_MODE_CONNECTOR_LVDS,
  228. DRM_MODE_CONNECTOR_9PinDIN,
  229. DRM_MODE_CONNECTOR_Unknown,
  230. DRM_MODE_CONNECTOR_Unknown,
  231. DRM_MODE_CONNECTOR_Unknown,
  232. DRM_MODE_CONNECTOR_DisplayPort
  233. };
  234. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  235. {
  236. struct radeon_device *rdev = dev->dev_private;
  237. struct radeon_mode_info *mode_info = &rdev->mode_info;
  238. struct atom_context *ctx = mode_info->atom_context;
  239. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  240. uint16_t size, data_offset;
  241. uint8_t frev, crev, line_mux = 0;
  242. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  243. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  244. ATOM_OBJECT_HEADER *obj_header;
  245. int i, j, path_size, device_support;
  246. int connector_type;
  247. uint16_t igp_lane_info, conn_id, connector_object_id;
  248. bool linkb;
  249. struct radeon_i2c_bus_rec ddc_bus;
  250. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  251. if (data_offset == 0)
  252. return false;
  253. if (crev < 2)
  254. return false;
  255. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  256. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  257. (ctx->bios + data_offset +
  258. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  259. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  260. (ctx->bios + data_offset +
  261. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  262. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  263. path_size = 0;
  264. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  265. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  266. ATOM_DISPLAY_OBJECT_PATH *path;
  267. addr += path_size;
  268. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  269. path_size += le16_to_cpu(path->usSize);
  270. linkb = false;
  271. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  272. uint8_t con_obj_id, con_obj_num, con_obj_type;
  273. con_obj_id =
  274. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  275. >> OBJECT_ID_SHIFT;
  276. con_obj_num =
  277. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  278. >> ENUM_ID_SHIFT;
  279. con_obj_type =
  280. (le16_to_cpu(path->usConnObjectId) &
  281. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  282. /* TODO CV support */
  283. if (le16_to_cpu(path->usDeviceTag) ==
  284. ATOM_DEVICE_CV_SUPPORT)
  285. continue;
  286. /* IGP chips */
  287. if ((rdev->flags & RADEON_IS_IGP) &&
  288. (con_obj_id ==
  289. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  290. uint16_t igp_offset = 0;
  291. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  292. index =
  293. GetIndexIntoMasterTable(DATA,
  294. IntegratedSystemInfo);
  295. atom_parse_data_header(ctx, index, &size, &frev,
  296. &crev, &igp_offset);
  297. if (crev >= 2) {
  298. igp_obj =
  299. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  300. *) (ctx->bios + igp_offset);
  301. if (igp_obj) {
  302. uint32_t slot_config, ct;
  303. if (con_obj_num == 1)
  304. slot_config =
  305. igp_obj->
  306. ulDDISlot1Config;
  307. else
  308. slot_config =
  309. igp_obj->
  310. ulDDISlot2Config;
  311. ct = (slot_config >> 16) & 0xff;
  312. connector_type =
  313. object_connector_convert
  314. [ct];
  315. connector_object_id = ct;
  316. igp_lane_info =
  317. slot_config & 0xffff;
  318. } else
  319. continue;
  320. } else
  321. continue;
  322. } else {
  323. igp_lane_info = 0;
  324. connector_type =
  325. object_connector_convert[con_obj_id];
  326. connector_object_id = con_obj_id;
  327. }
  328. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  329. continue;
  330. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
  331. j++) {
  332. uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
  333. enc_obj_id =
  334. (le16_to_cpu(path->usGraphicObjIds[j]) &
  335. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  336. enc_obj_num =
  337. (le16_to_cpu(path->usGraphicObjIds[j]) &
  338. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  339. enc_obj_type =
  340. (le16_to_cpu(path->usGraphicObjIds[j]) &
  341. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  342. /* FIXME: add support for router objects */
  343. if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  344. if (enc_obj_num == 2)
  345. linkb = true;
  346. else
  347. linkb = false;
  348. radeon_add_atom_encoder(dev,
  349. enc_obj_id,
  350. le16_to_cpu
  351. (path->
  352. usDeviceTag));
  353. }
  354. }
  355. /* look up gpio for ddc */
  356. if ((le16_to_cpu(path->usDeviceTag) &
  357. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  358. == 0) {
  359. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  360. if (le16_to_cpu(path->usConnObjectId) ==
  361. le16_to_cpu(con_obj->asObjects[j].
  362. usObjectID)) {
  363. ATOM_COMMON_RECORD_HEADER
  364. *record =
  365. (ATOM_COMMON_RECORD_HEADER
  366. *)
  367. (ctx->bios + data_offset +
  368. le16_to_cpu(con_obj->
  369. asObjects[j].
  370. usRecordOffset));
  371. ATOM_I2C_RECORD *i2c_record;
  372. while (record->ucRecordType > 0
  373. && record->
  374. ucRecordType <=
  375. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  376. switch (record->
  377. ucRecordType) {
  378. case ATOM_I2C_RECORD_TYPE:
  379. i2c_record =
  380. (ATOM_I2C_RECORD
  381. *) record;
  382. line_mux =
  383. i2c_record->
  384. sucI2cId.
  385. bfI2C_LineMux;
  386. break;
  387. }
  388. record =
  389. (ATOM_COMMON_RECORD_HEADER
  390. *) ((char *)record
  391. +
  392. record->
  393. ucRecordSize);
  394. }
  395. break;
  396. }
  397. }
  398. } else
  399. line_mux = 0;
  400. if ((le16_to_cpu(path->usDeviceTag) ==
  401. ATOM_DEVICE_TV1_SUPPORT)
  402. || (le16_to_cpu(path->usDeviceTag) ==
  403. ATOM_DEVICE_TV2_SUPPORT)
  404. || (le16_to_cpu(path->usDeviceTag) ==
  405. ATOM_DEVICE_CV_SUPPORT))
  406. ddc_bus.valid = false;
  407. else
  408. ddc_bus = radeon_lookup_gpio(dev, line_mux);
  409. conn_id = le16_to_cpu(path->usConnObjectId);
  410. if (!radeon_atom_apply_quirks
  411. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  412. &ddc_bus, &conn_id))
  413. continue;
  414. radeon_add_atom_connector(dev,
  415. conn_id,
  416. le16_to_cpu(path->
  417. usDeviceTag),
  418. connector_type, &ddc_bus,
  419. linkb, igp_lane_info,
  420. connector_object_id);
  421. }
  422. }
  423. radeon_link_encoder_connector(dev);
  424. return true;
  425. }
  426. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  427. int connector_type,
  428. uint16_t devices)
  429. {
  430. struct radeon_device *rdev = dev->dev_private;
  431. if (rdev->flags & RADEON_IS_IGP) {
  432. return supported_devices_connector_object_id_convert
  433. [connector_type];
  434. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  435. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  436. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  437. struct radeon_mode_info *mode_info = &rdev->mode_info;
  438. struct atom_context *ctx = mode_info->atom_context;
  439. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  440. uint16_t size, data_offset;
  441. uint8_t frev, crev;
  442. ATOM_XTMDS_INFO *xtmds;
  443. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  444. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  445. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  446. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  447. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  448. else
  449. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  450. } else {
  451. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  452. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  453. else
  454. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  455. }
  456. } else {
  457. return supported_devices_connector_object_id_convert
  458. [connector_type];
  459. }
  460. }
  461. struct bios_connector {
  462. bool valid;
  463. uint16_t line_mux;
  464. uint16_t devices;
  465. int connector_type;
  466. struct radeon_i2c_bus_rec ddc_bus;
  467. };
  468. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  469. drm_device
  470. *dev)
  471. {
  472. struct radeon_device *rdev = dev->dev_private;
  473. struct radeon_mode_info *mode_info = &rdev->mode_info;
  474. struct atom_context *ctx = mode_info->atom_context;
  475. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  476. uint16_t size, data_offset;
  477. uint8_t frev, crev;
  478. uint16_t device_support;
  479. uint8_t dac;
  480. union atom_supported_devices *supported_devices;
  481. int i, j;
  482. struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
  483. atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
  484. supported_devices =
  485. (union atom_supported_devices *)(ctx->bios + data_offset);
  486. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  487. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  488. ATOM_CONNECTOR_INFO_I2C ci =
  489. supported_devices->info.asConnInfo[i];
  490. bios_connectors[i].valid = false;
  491. if (!(device_support & (1 << i))) {
  492. continue;
  493. }
  494. if (i == ATOM_DEVICE_CV_INDEX) {
  495. DRM_DEBUG("Skipping Component Video\n");
  496. continue;
  497. }
  498. bios_connectors[i].connector_type =
  499. supported_devices_connector_convert[ci.sucConnectorInfo.
  500. sbfAccess.
  501. bfConnectorType];
  502. if (bios_connectors[i].connector_type ==
  503. DRM_MODE_CONNECTOR_Unknown)
  504. continue;
  505. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  506. if ((rdev->family == CHIP_RS690) ||
  507. (rdev->family == CHIP_RS740)) {
  508. if ((i == ATOM_DEVICE_DFP2_INDEX)
  509. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
  510. bios_connectors[i].line_mux =
  511. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  512. else if ((i == ATOM_DEVICE_DFP3_INDEX)
  513. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
  514. bios_connectors[i].line_mux =
  515. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  516. else
  517. bios_connectors[i].line_mux =
  518. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  519. } else
  520. bios_connectors[i].line_mux =
  521. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  522. /* give tv unique connector ids */
  523. if (i == ATOM_DEVICE_TV1_INDEX) {
  524. bios_connectors[i].ddc_bus.valid = false;
  525. bios_connectors[i].line_mux = 50;
  526. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  527. bios_connectors[i].ddc_bus.valid = false;
  528. bios_connectors[i].line_mux = 51;
  529. } else if (i == ATOM_DEVICE_CV_INDEX) {
  530. bios_connectors[i].ddc_bus.valid = false;
  531. bios_connectors[i].line_mux = 52;
  532. } else
  533. bios_connectors[i].ddc_bus =
  534. radeon_lookup_gpio(dev,
  535. bios_connectors[i].line_mux);
  536. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  537. * shared with a DVI port, we'll pick up the DVI connector when we
  538. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  539. */
  540. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  541. bios_connectors[i].connector_type =
  542. DRM_MODE_CONNECTOR_VGA;
  543. if (!radeon_atom_apply_quirks
  544. (dev, (1 << i), &bios_connectors[i].connector_type,
  545. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux))
  546. continue;
  547. bios_connectors[i].valid = true;
  548. bios_connectors[i].devices = (1 << i);
  549. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  550. radeon_add_atom_encoder(dev,
  551. radeon_get_encoder_id(dev,
  552. (1 << i),
  553. dac),
  554. (1 << i));
  555. else
  556. radeon_add_legacy_encoder(dev,
  557. radeon_get_encoder_id(dev,
  558. (1 <<
  559. i),
  560. dac),
  561. (1 << i));
  562. }
  563. /* combine shared connectors */
  564. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  565. if (bios_connectors[i].valid) {
  566. for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
  567. if (bios_connectors[j].valid && (i != j)) {
  568. if (bios_connectors[i].line_mux ==
  569. bios_connectors[j].line_mux) {
  570. if (((bios_connectors[i].
  571. devices &
  572. (ATOM_DEVICE_DFP_SUPPORT))
  573. && (bios_connectors[j].
  574. devices &
  575. (ATOM_DEVICE_CRT_SUPPORT)))
  576. ||
  577. ((bios_connectors[j].
  578. devices &
  579. (ATOM_DEVICE_DFP_SUPPORT))
  580. && (bios_connectors[i].
  581. devices &
  582. (ATOM_DEVICE_CRT_SUPPORT)))) {
  583. bios_connectors[i].
  584. devices |=
  585. bios_connectors[j].
  586. devices;
  587. bios_connectors[i].
  588. connector_type =
  589. DRM_MODE_CONNECTOR_DVII;
  590. bios_connectors[j].
  591. valid = false;
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }
  598. /* add the connectors */
  599. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  600. if (bios_connectors[i].valid) {
  601. uint16_t connector_object_id =
  602. atombios_get_connector_object_id(dev,
  603. bios_connectors[i].connector_type,
  604. bios_connectors[i].devices);
  605. radeon_add_atom_connector(dev,
  606. bios_connectors[i].line_mux,
  607. bios_connectors[i].devices,
  608. bios_connectors[i].
  609. connector_type,
  610. &bios_connectors[i].ddc_bus,
  611. false, 0,
  612. connector_object_id);
  613. }
  614. }
  615. radeon_link_encoder_connector(dev);
  616. return true;
  617. }
  618. union firmware_info {
  619. ATOM_FIRMWARE_INFO info;
  620. ATOM_FIRMWARE_INFO_V1_2 info_12;
  621. ATOM_FIRMWARE_INFO_V1_3 info_13;
  622. ATOM_FIRMWARE_INFO_V1_4 info_14;
  623. };
  624. bool radeon_atom_get_clock_info(struct drm_device *dev)
  625. {
  626. struct radeon_device *rdev = dev->dev_private;
  627. struct radeon_mode_info *mode_info = &rdev->mode_info;
  628. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  629. union firmware_info *firmware_info;
  630. uint8_t frev, crev;
  631. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  632. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  633. struct radeon_pll *spll = &rdev->clock.spll;
  634. struct radeon_pll *mpll = &rdev->clock.mpll;
  635. uint16_t data_offset;
  636. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  637. &crev, &data_offset);
  638. firmware_info =
  639. (union firmware_info *)(mode_info->atom_context->bios +
  640. data_offset);
  641. if (firmware_info) {
  642. /* pixel clocks */
  643. p1pll->reference_freq =
  644. le16_to_cpu(firmware_info->info.usReferenceClock);
  645. p1pll->reference_div = 0;
  646. if (crev < 2)
  647. p1pll->pll_out_min =
  648. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  649. else
  650. p1pll->pll_out_min =
  651. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  652. p1pll->pll_out_max =
  653. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  654. if (p1pll->pll_out_min == 0) {
  655. if (ASIC_IS_AVIVO(rdev))
  656. p1pll->pll_out_min = 64800;
  657. else
  658. p1pll->pll_out_min = 20000;
  659. } else if (p1pll->pll_out_min > 64800) {
  660. /* Limiting the pll output range is a good thing generally as
  661. * it limits the number of possible pll combinations for a given
  662. * frequency presumably to the ones that work best on each card.
  663. * However, certain duallink DVI monitors seem to like
  664. * pll combinations that would be limited by this at least on
  665. * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
  666. * family.
  667. */
  668. p1pll->pll_out_min = 64800;
  669. }
  670. p1pll->pll_in_min =
  671. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  672. p1pll->pll_in_max =
  673. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  674. *p2pll = *p1pll;
  675. /* system clock */
  676. spll->reference_freq =
  677. le16_to_cpu(firmware_info->info.usReferenceClock);
  678. spll->reference_div = 0;
  679. spll->pll_out_min =
  680. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  681. spll->pll_out_max =
  682. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  683. /* ??? */
  684. if (spll->pll_out_min == 0) {
  685. if (ASIC_IS_AVIVO(rdev))
  686. spll->pll_out_min = 64800;
  687. else
  688. spll->pll_out_min = 20000;
  689. }
  690. spll->pll_in_min =
  691. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  692. spll->pll_in_max =
  693. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  694. /* memory clock */
  695. mpll->reference_freq =
  696. le16_to_cpu(firmware_info->info.usReferenceClock);
  697. mpll->reference_div = 0;
  698. mpll->pll_out_min =
  699. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  700. mpll->pll_out_max =
  701. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  702. /* ??? */
  703. if (mpll->pll_out_min == 0) {
  704. if (ASIC_IS_AVIVO(rdev))
  705. mpll->pll_out_min = 64800;
  706. else
  707. mpll->pll_out_min = 20000;
  708. }
  709. mpll->pll_in_min =
  710. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  711. mpll->pll_in_max =
  712. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  713. rdev->clock.default_sclk =
  714. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  715. rdev->clock.default_mclk =
  716. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  717. return true;
  718. }
  719. return false;
  720. }
  721. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  722. struct radeon_encoder_int_tmds *tmds)
  723. {
  724. struct drm_device *dev = encoder->base.dev;
  725. struct radeon_device *rdev = dev->dev_private;
  726. struct radeon_mode_info *mode_info = &rdev->mode_info;
  727. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  728. uint16_t data_offset;
  729. struct _ATOM_TMDS_INFO *tmds_info;
  730. uint8_t frev, crev;
  731. uint16_t maxfreq;
  732. int i;
  733. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  734. &crev, &data_offset);
  735. tmds_info =
  736. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  737. data_offset);
  738. if (tmds_info) {
  739. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  740. for (i = 0; i < 4; i++) {
  741. tmds->tmds_pll[i].freq =
  742. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  743. tmds->tmds_pll[i].value =
  744. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  745. tmds->tmds_pll[i].value |=
  746. (tmds_info->asMiscInfo[i].
  747. ucPLL_VCO_Gain & 0x3f) << 6;
  748. tmds->tmds_pll[i].value |=
  749. (tmds_info->asMiscInfo[i].
  750. ucPLL_DutyCycle & 0xf) << 12;
  751. tmds->tmds_pll[i].value |=
  752. (tmds_info->asMiscInfo[i].
  753. ucPLL_VoltageSwing & 0xf) << 16;
  754. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  755. tmds->tmds_pll[i].freq,
  756. tmds->tmds_pll[i].value);
  757. if (maxfreq == tmds->tmds_pll[i].freq) {
  758. tmds->tmds_pll[i].freq = 0xffffffff;
  759. break;
  760. }
  761. }
  762. return true;
  763. }
  764. return false;
  765. }
  766. static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
  767. radeon_encoder
  768. *encoder,
  769. int id)
  770. {
  771. struct drm_device *dev = encoder->base.dev;
  772. struct radeon_device *rdev = dev->dev_private;
  773. struct radeon_mode_info *mode_info = &rdev->mode_info;
  774. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  775. uint16_t data_offset;
  776. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  777. uint8_t frev, crev;
  778. struct radeon_atom_ss *ss = NULL;
  779. if (id > ATOM_MAX_SS_ENTRY)
  780. return NULL;
  781. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  782. &crev, &data_offset);
  783. ss_info =
  784. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  785. if (ss_info) {
  786. ss =
  787. kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
  788. if (!ss)
  789. return NULL;
  790. ss->percentage = le16_to_cpu(ss_info->asSS_Info[id].usSpreadSpectrumPercentage);
  791. ss->type = ss_info->asSS_Info[id].ucSpreadSpectrumType;
  792. ss->step = ss_info->asSS_Info[id].ucSS_Step;
  793. ss->delay = ss_info->asSS_Info[id].ucSS_Delay;
  794. ss->range = ss_info->asSS_Info[id].ucSS_Range;
  795. ss->refdiv = ss_info->asSS_Info[id].ucRecommendedRef_Div;
  796. }
  797. return ss;
  798. }
  799. union lvds_info {
  800. struct _ATOM_LVDS_INFO info;
  801. struct _ATOM_LVDS_INFO_V12 info_12;
  802. };
  803. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  804. radeon_encoder
  805. *encoder)
  806. {
  807. struct drm_device *dev = encoder->base.dev;
  808. struct radeon_device *rdev = dev->dev_private;
  809. struct radeon_mode_info *mode_info = &rdev->mode_info;
  810. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  811. uint16_t data_offset, misc;
  812. union lvds_info *lvds_info;
  813. uint8_t frev, crev;
  814. struct radeon_encoder_atom_dig *lvds = NULL;
  815. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  816. &crev, &data_offset);
  817. lvds_info =
  818. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  819. if (lvds_info) {
  820. lvds =
  821. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  822. if (!lvds)
  823. return NULL;
  824. lvds->native_mode.clock =
  825. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  826. lvds->native_mode.hdisplay =
  827. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  828. lvds->native_mode.vdisplay =
  829. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  830. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  831. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  832. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  833. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  834. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  835. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  836. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  837. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  838. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  839. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  840. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  841. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  842. lvds->panel_pwr_delay =
  843. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  844. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  845. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  846. if (misc & ATOM_VSYNC_POLARITY)
  847. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  848. if (misc & ATOM_HSYNC_POLARITY)
  849. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  850. if (misc & ATOM_COMPOSITESYNC)
  851. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  852. if (misc & ATOM_INTERLACE)
  853. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  854. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  855. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  856. /* set crtc values */
  857. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  858. lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
  859. encoder->native_mode = lvds->native_mode;
  860. }
  861. return lvds;
  862. }
  863. struct radeon_encoder_primary_dac *
  864. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  865. {
  866. struct drm_device *dev = encoder->base.dev;
  867. struct radeon_device *rdev = dev->dev_private;
  868. struct radeon_mode_info *mode_info = &rdev->mode_info;
  869. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  870. uint16_t data_offset;
  871. struct _COMPASSIONATE_DATA *dac_info;
  872. uint8_t frev, crev;
  873. uint8_t bg, dac;
  874. struct radeon_encoder_primary_dac *p_dac = NULL;
  875. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  876. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  877. if (dac_info) {
  878. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  879. if (!p_dac)
  880. return NULL;
  881. bg = dac_info->ucDAC1_BG_Adjustment;
  882. dac = dac_info->ucDAC1_DAC_Adjustment;
  883. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  884. }
  885. return p_dac;
  886. }
  887. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  888. struct drm_display_mode *mode)
  889. {
  890. struct radeon_mode_info *mode_info = &rdev->mode_info;
  891. ATOM_ANALOG_TV_INFO *tv_info;
  892. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  893. ATOM_DTD_FORMAT *dtd_timings;
  894. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  895. u8 frev, crev;
  896. u16 data_offset, misc;
  897. atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
  898. switch (crev) {
  899. case 1:
  900. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  901. if (index > MAX_SUPPORTED_TV_TIMING)
  902. return false;
  903. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  904. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  905. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  906. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  907. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  908. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  909. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  910. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  911. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  912. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  913. mode->flags = 0;
  914. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  915. if (misc & ATOM_VSYNC_POLARITY)
  916. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  917. if (misc & ATOM_HSYNC_POLARITY)
  918. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  919. if (misc & ATOM_COMPOSITESYNC)
  920. mode->flags |= DRM_MODE_FLAG_CSYNC;
  921. if (misc & ATOM_INTERLACE)
  922. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  923. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  924. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  925. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  926. if (index == 1) {
  927. /* PAL timings appear to have wrong values for totals */
  928. mode->crtc_htotal -= 1;
  929. mode->crtc_vtotal -= 1;
  930. }
  931. break;
  932. case 2:
  933. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  934. if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
  935. return false;
  936. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  937. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  938. le16_to_cpu(dtd_timings->usHBlanking_Time);
  939. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  940. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  941. le16_to_cpu(dtd_timings->usHSyncOffset);
  942. mode->crtc_hsync_end = mode->crtc_hsync_start +
  943. le16_to_cpu(dtd_timings->usHSyncWidth);
  944. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  945. le16_to_cpu(dtd_timings->usVBlanking_Time);
  946. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  947. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  948. le16_to_cpu(dtd_timings->usVSyncOffset);
  949. mode->crtc_vsync_end = mode->crtc_vsync_start +
  950. le16_to_cpu(dtd_timings->usVSyncWidth);
  951. mode->flags = 0;
  952. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  953. if (misc & ATOM_VSYNC_POLARITY)
  954. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  955. if (misc & ATOM_HSYNC_POLARITY)
  956. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  957. if (misc & ATOM_COMPOSITESYNC)
  958. mode->flags |= DRM_MODE_FLAG_CSYNC;
  959. if (misc & ATOM_INTERLACE)
  960. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  961. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  962. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  963. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  964. break;
  965. }
  966. return true;
  967. }
  968. struct radeon_encoder_tv_dac *
  969. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  970. {
  971. struct drm_device *dev = encoder->base.dev;
  972. struct radeon_device *rdev = dev->dev_private;
  973. struct radeon_mode_info *mode_info = &rdev->mode_info;
  974. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  975. uint16_t data_offset;
  976. struct _COMPASSIONATE_DATA *dac_info;
  977. uint8_t frev, crev;
  978. uint8_t bg, dac;
  979. struct radeon_encoder_tv_dac *tv_dac = NULL;
  980. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  981. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  982. if (dac_info) {
  983. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  984. if (!tv_dac)
  985. return NULL;
  986. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  987. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  988. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  989. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  990. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  991. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  992. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  993. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  994. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  995. }
  996. return tv_dac;
  997. }
  998. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  999. {
  1000. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  1001. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  1002. args.ucEnable = enable;
  1003. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1004. }
  1005. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  1006. {
  1007. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  1008. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  1009. args.ucEnable = enable;
  1010. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1011. }
  1012. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  1013. {
  1014. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  1015. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  1016. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1017. return args.ulReturnEngineClock;
  1018. }
  1019. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  1020. {
  1021. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  1022. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  1023. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1024. return args.ulReturnMemoryClock;
  1025. }
  1026. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  1027. uint32_t eng_clock)
  1028. {
  1029. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  1030. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  1031. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  1032. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1033. }
  1034. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  1035. uint32_t mem_clock)
  1036. {
  1037. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  1038. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  1039. if (rdev->flags & RADEON_IS_IGP)
  1040. return;
  1041. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  1042. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1043. }
  1044. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  1045. {
  1046. struct radeon_device *rdev = dev->dev_private;
  1047. uint32_t bios_2_scratch, bios_6_scratch;
  1048. if (rdev->family >= CHIP_R600) {
  1049. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1050. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1051. } else {
  1052. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1053. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1054. }
  1055. /* let the bios control the backlight */
  1056. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  1057. /* tell the bios not to handle mode switching */
  1058. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  1059. if (rdev->family >= CHIP_R600) {
  1060. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1061. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1062. } else {
  1063. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1064. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1065. }
  1066. }
  1067. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  1068. {
  1069. uint32_t scratch_reg;
  1070. int i;
  1071. if (rdev->family >= CHIP_R600)
  1072. scratch_reg = R600_BIOS_0_SCRATCH;
  1073. else
  1074. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1075. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1076. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  1077. }
  1078. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  1079. {
  1080. uint32_t scratch_reg;
  1081. int i;
  1082. if (rdev->family >= CHIP_R600)
  1083. scratch_reg = R600_BIOS_0_SCRATCH;
  1084. else
  1085. scratch_reg = RADEON_BIOS_0_SCRATCH;
  1086. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  1087. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  1088. }
  1089. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  1090. {
  1091. struct drm_device *dev = encoder->dev;
  1092. struct radeon_device *rdev = dev->dev_private;
  1093. uint32_t bios_6_scratch;
  1094. if (rdev->family >= CHIP_R600)
  1095. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1096. else
  1097. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1098. if (lock)
  1099. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  1100. else
  1101. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  1102. if (rdev->family >= CHIP_R600)
  1103. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1104. else
  1105. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1106. }
  1107. /* at some point we may want to break this out into individual functions */
  1108. void
  1109. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  1110. struct drm_encoder *encoder,
  1111. bool connected)
  1112. {
  1113. struct drm_device *dev = connector->dev;
  1114. struct radeon_device *rdev = dev->dev_private;
  1115. struct radeon_connector *radeon_connector =
  1116. to_radeon_connector(connector);
  1117. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1118. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  1119. if (rdev->family >= CHIP_R600) {
  1120. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  1121. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1122. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  1123. } else {
  1124. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  1125. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1126. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  1127. }
  1128. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  1129. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  1130. if (connected) {
  1131. DRM_DEBUG("TV1 connected\n");
  1132. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  1133. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  1134. } else {
  1135. DRM_DEBUG("TV1 disconnected\n");
  1136. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  1137. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  1138. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  1139. }
  1140. }
  1141. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  1142. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  1143. if (connected) {
  1144. DRM_DEBUG("CV connected\n");
  1145. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  1146. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  1147. } else {
  1148. DRM_DEBUG("CV disconnected\n");
  1149. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  1150. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  1151. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  1152. }
  1153. }
  1154. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  1155. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  1156. if (connected) {
  1157. DRM_DEBUG("LCD1 connected\n");
  1158. bios_0_scratch |= ATOM_S0_LCD1;
  1159. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  1160. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  1161. } else {
  1162. DRM_DEBUG("LCD1 disconnected\n");
  1163. bios_0_scratch &= ~ATOM_S0_LCD1;
  1164. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  1165. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  1166. }
  1167. }
  1168. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  1169. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  1170. if (connected) {
  1171. DRM_DEBUG("CRT1 connected\n");
  1172. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  1173. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  1174. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  1175. } else {
  1176. DRM_DEBUG("CRT1 disconnected\n");
  1177. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  1178. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  1179. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  1180. }
  1181. }
  1182. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  1183. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  1184. if (connected) {
  1185. DRM_DEBUG("CRT2 connected\n");
  1186. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  1187. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  1188. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  1189. } else {
  1190. DRM_DEBUG("CRT2 disconnected\n");
  1191. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  1192. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  1193. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  1194. }
  1195. }
  1196. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  1197. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  1198. if (connected) {
  1199. DRM_DEBUG("DFP1 connected\n");
  1200. bios_0_scratch |= ATOM_S0_DFP1;
  1201. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  1202. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  1203. } else {
  1204. DRM_DEBUG("DFP1 disconnected\n");
  1205. bios_0_scratch &= ~ATOM_S0_DFP1;
  1206. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  1207. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  1208. }
  1209. }
  1210. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  1211. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  1212. if (connected) {
  1213. DRM_DEBUG("DFP2 connected\n");
  1214. bios_0_scratch |= ATOM_S0_DFP2;
  1215. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  1216. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  1217. } else {
  1218. DRM_DEBUG("DFP2 disconnected\n");
  1219. bios_0_scratch &= ~ATOM_S0_DFP2;
  1220. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  1221. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  1222. }
  1223. }
  1224. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  1225. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  1226. if (connected) {
  1227. DRM_DEBUG("DFP3 connected\n");
  1228. bios_0_scratch |= ATOM_S0_DFP3;
  1229. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  1230. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  1231. } else {
  1232. DRM_DEBUG("DFP3 disconnected\n");
  1233. bios_0_scratch &= ~ATOM_S0_DFP3;
  1234. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  1235. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  1236. }
  1237. }
  1238. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  1239. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  1240. if (connected) {
  1241. DRM_DEBUG("DFP4 connected\n");
  1242. bios_0_scratch |= ATOM_S0_DFP4;
  1243. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  1244. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  1245. } else {
  1246. DRM_DEBUG("DFP4 disconnected\n");
  1247. bios_0_scratch &= ~ATOM_S0_DFP4;
  1248. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  1249. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  1250. }
  1251. }
  1252. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  1253. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  1254. if (connected) {
  1255. DRM_DEBUG("DFP5 connected\n");
  1256. bios_0_scratch |= ATOM_S0_DFP5;
  1257. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  1258. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  1259. } else {
  1260. DRM_DEBUG("DFP5 disconnected\n");
  1261. bios_0_scratch &= ~ATOM_S0_DFP5;
  1262. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1263. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1264. }
  1265. }
  1266. if (rdev->family >= CHIP_R600) {
  1267. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1268. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1269. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1270. } else {
  1271. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1272. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1273. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1274. }
  1275. }
  1276. void
  1277. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1278. {
  1279. struct drm_device *dev = encoder->dev;
  1280. struct radeon_device *rdev = dev->dev_private;
  1281. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1282. uint32_t bios_3_scratch;
  1283. if (rdev->family >= CHIP_R600)
  1284. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1285. else
  1286. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1287. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1288. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1289. bios_3_scratch |= (crtc << 18);
  1290. }
  1291. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1292. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1293. bios_3_scratch |= (crtc << 24);
  1294. }
  1295. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1296. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1297. bios_3_scratch |= (crtc << 16);
  1298. }
  1299. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1300. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1301. bios_3_scratch |= (crtc << 20);
  1302. }
  1303. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1304. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1305. bios_3_scratch |= (crtc << 17);
  1306. }
  1307. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1308. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1309. bios_3_scratch |= (crtc << 19);
  1310. }
  1311. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1312. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1313. bios_3_scratch |= (crtc << 23);
  1314. }
  1315. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1316. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1317. bios_3_scratch |= (crtc << 25);
  1318. }
  1319. if (rdev->family >= CHIP_R600)
  1320. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1321. else
  1322. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1323. }
  1324. void
  1325. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1326. {
  1327. struct drm_device *dev = encoder->dev;
  1328. struct radeon_device *rdev = dev->dev_private;
  1329. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1330. uint32_t bios_2_scratch;
  1331. if (rdev->family >= CHIP_R600)
  1332. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1333. else
  1334. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1335. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1336. if (on)
  1337. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1338. else
  1339. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1340. }
  1341. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1342. if (on)
  1343. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1344. else
  1345. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1346. }
  1347. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1348. if (on)
  1349. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1350. else
  1351. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1352. }
  1353. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1354. if (on)
  1355. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1356. else
  1357. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1358. }
  1359. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1360. if (on)
  1361. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1362. else
  1363. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1364. }
  1365. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1366. if (on)
  1367. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1368. else
  1369. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1370. }
  1371. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1372. if (on)
  1373. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1374. else
  1375. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1376. }
  1377. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1378. if (on)
  1379. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1380. else
  1381. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1382. }
  1383. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1384. if (on)
  1385. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1386. else
  1387. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1388. }
  1389. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1390. if (on)
  1391. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1392. else
  1393. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1394. }
  1395. if (rdev->family >= CHIP_R600)
  1396. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1397. else
  1398. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1399. }