radeon_atombios.c 42 KB

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