radeon_atombios.c 47 KB

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