radeon_atombios.c 47 KB

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