radeon_atombios.c 41 KB

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