radeon_atombios.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. if (i == ATOM_DEVICE_TV1_INDEX) {
  414. DRM_DEBUG("Skipping TV Out\n");
  415. continue;
  416. }
  417. bios_connectors[i].connector_type =
  418. supported_devices_connector_convert[ci.sucConnectorInfo.
  419. sbfAccess.
  420. bfConnectorType];
  421. if (bios_connectors[i].connector_type ==
  422. DRM_MODE_CONNECTOR_Unknown)
  423. continue;
  424. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  425. if ((rdev->family == CHIP_RS690) ||
  426. (rdev->family == CHIP_RS740)) {
  427. if ((i == ATOM_DEVICE_DFP2_INDEX)
  428. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
  429. bios_connectors[i].line_mux =
  430. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  431. else if ((i == ATOM_DEVICE_DFP3_INDEX)
  432. && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
  433. bios_connectors[i].line_mux =
  434. ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
  435. else
  436. bios_connectors[i].line_mux =
  437. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  438. } else
  439. bios_connectors[i].line_mux =
  440. ci.sucI2cId.sbfAccess.bfI2C_LineMux;
  441. /* give tv unique connector ids */
  442. if (i == ATOM_DEVICE_TV1_INDEX) {
  443. bios_connectors[i].ddc_bus.valid = false;
  444. bios_connectors[i].line_mux = 50;
  445. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  446. bios_connectors[i].ddc_bus.valid = false;
  447. bios_connectors[i].line_mux = 51;
  448. } else if (i == ATOM_DEVICE_CV_INDEX) {
  449. bios_connectors[i].ddc_bus.valid = false;
  450. bios_connectors[i].line_mux = 52;
  451. } else
  452. bios_connectors[i].ddc_bus =
  453. radeon_lookup_gpio(dev,
  454. bios_connectors[i].line_mux);
  455. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  456. * shared with a DVI port, we'll pick up the DVI connector when we
  457. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  458. */
  459. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  460. bios_connectors[i].connector_type =
  461. DRM_MODE_CONNECTOR_VGA;
  462. if (!radeon_atom_apply_quirks
  463. (dev, (1 << i), &bios_connectors[i].connector_type,
  464. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux))
  465. continue;
  466. bios_connectors[i].valid = true;
  467. bios_connectors[i].devices = (1 << i);
  468. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  469. radeon_add_atom_encoder(dev,
  470. radeon_get_encoder_id(dev,
  471. (1 << i),
  472. dac),
  473. (1 << i));
  474. else
  475. radeon_add_legacy_encoder(dev,
  476. radeon_get_encoder_id(dev,
  477. (1 <<
  478. i),
  479. dac),
  480. (1 << i));
  481. }
  482. /* combine shared connectors */
  483. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  484. if (bios_connectors[i].valid) {
  485. for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
  486. if (bios_connectors[j].valid && (i != j)) {
  487. if (bios_connectors[i].line_mux ==
  488. bios_connectors[j].line_mux) {
  489. if (((bios_connectors[i].
  490. devices &
  491. (ATOM_DEVICE_DFP_SUPPORT))
  492. && (bios_connectors[j].
  493. devices &
  494. (ATOM_DEVICE_CRT_SUPPORT)))
  495. ||
  496. ((bios_connectors[j].
  497. devices &
  498. (ATOM_DEVICE_DFP_SUPPORT))
  499. && (bios_connectors[i].
  500. devices &
  501. (ATOM_DEVICE_CRT_SUPPORT)))) {
  502. bios_connectors[i].
  503. devices |=
  504. bios_connectors[j].
  505. devices;
  506. bios_connectors[i].
  507. connector_type =
  508. DRM_MODE_CONNECTOR_DVII;
  509. bios_connectors[j].
  510. valid = false;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. /* add the connectors */
  518. for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
  519. if (bios_connectors[i].valid)
  520. radeon_add_atom_connector(dev,
  521. bios_connectors[i].line_mux,
  522. bios_connectors[i].devices,
  523. bios_connectors[i].
  524. connector_type,
  525. &bios_connectors[i].ddc_bus,
  526. false, 0);
  527. }
  528. radeon_link_encoder_connector(dev);
  529. return true;
  530. }
  531. union firmware_info {
  532. ATOM_FIRMWARE_INFO info;
  533. ATOM_FIRMWARE_INFO_V1_2 info_12;
  534. ATOM_FIRMWARE_INFO_V1_3 info_13;
  535. ATOM_FIRMWARE_INFO_V1_4 info_14;
  536. };
  537. bool radeon_atom_get_clock_info(struct drm_device *dev)
  538. {
  539. struct radeon_device *rdev = dev->dev_private;
  540. struct radeon_mode_info *mode_info = &rdev->mode_info;
  541. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  542. union firmware_info *firmware_info;
  543. uint8_t frev, crev;
  544. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  545. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  546. struct radeon_pll *spll = &rdev->clock.spll;
  547. struct radeon_pll *mpll = &rdev->clock.mpll;
  548. uint16_t data_offset;
  549. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  550. &crev, &data_offset);
  551. firmware_info =
  552. (union firmware_info *)(mode_info->atom_context->bios +
  553. data_offset);
  554. if (firmware_info) {
  555. /* pixel clocks */
  556. p1pll->reference_freq =
  557. le16_to_cpu(firmware_info->info.usReferenceClock);
  558. p1pll->reference_div = 0;
  559. p1pll->pll_out_min =
  560. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  561. p1pll->pll_out_max =
  562. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  563. if (p1pll->pll_out_min == 0) {
  564. if (ASIC_IS_AVIVO(rdev))
  565. p1pll->pll_out_min = 64800;
  566. else
  567. p1pll->pll_out_min = 20000;
  568. }
  569. p1pll->pll_in_min =
  570. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  571. p1pll->pll_in_max =
  572. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  573. *p2pll = *p1pll;
  574. /* system clock */
  575. spll->reference_freq =
  576. le16_to_cpu(firmware_info->info.usReferenceClock);
  577. spll->reference_div = 0;
  578. spll->pll_out_min =
  579. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  580. spll->pll_out_max =
  581. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  582. /* ??? */
  583. if (spll->pll_out_min == 0) {
  584. if (ASIC_IS_AVIVO(rdev))
  585. spll->pll_out_min = 64800;
  586. else
  587. spll->pll_out_min = 20000;
  588. }
  589. spll->pll_in_min =
  590. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  591. spll->pll_in_max =
  592. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  593. /* memory clock */
  594. mpll->reference_freq =
  595. le16_to_cpu(firmware_info->info.usReferenceClock);
  596. mpll->reference_div = 0;
  597. mpll->pll_out_min =
  598. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  599. mpll->pll_out_max =
  600. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  601. /* ??? */
  602. if (mpll->pll_out_min == 0) {
  603. if (ASIC_IS_AVIVO(rdev))
  604. mpll->pll_out_min = 64800;
  605. else
  606. mpll->pll_out_min = 20000;
  607. }
  608. mpll->pll_in_min =
  609. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  610. mpll->pll_in_max =
  611. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  612. rdev->clock.default_sclk =
  613. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  614. rdev->clock.default_mclk =
  615. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  616. return true;
  617. }
  618. return false;
  619. }
  620. struct radeon_encoder_int_tmds *radeon_atombios_get_tmds_info(struct
  621. radeon_encoder
  622. *encoder)
  623. {
  624. struct drm_device *dev = encoder->base.dev;
  625. struct radeon_device *rdev = dev->dev_private;
  626. struct radeon_mode_info *mode_info = &rdev->mode_info;
  627. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  628. uint16_t data_offset;
  629. struct _ATOM_TMDS_INFO *tmds_info;
  630. uint8_t frev, crev;
  631. uint16_t maxfreq;
  632. int i;
  633. struct radeon_encoder_int_tmds *tmds = NULL;
  634. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  635. &crev, &data_offset);
  636. tmds_info =
  637. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  638. data_offset);
  639. if (tmds_info) {
  640. tmds =
  641. kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  642. if (!tmds)
  643. return NULL;
  644. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  645. for (i = 0; i < 4; i++) {
  646. tmds->tmds_pll[i].freq =
  647. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  648. tmds->tmds_pll[i].value =
  649. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  650. tmds->tmds_pll[i].value |=
  651. (tmds_info->asMiscInfo[i].
  652. ucPLL_VCO_Gain & 0x3f) << 6;
  653. tmds->tmds_pll[i].value |=
  654. (tmds_info->asMiscInfo[i].
  655. ucPLL_DutyCycle & 0xf) << 12;
  656. tmds->tmds_pll[i].value |=
  657. (tmds_info->asMiscInfo[i].
  658. ucPLL_VoltageSwing & 0xf) << 16;
  659. DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
  660. tmds->tmds_pll[i].freq,
  661. tmds->tmds_pll[i].value);
  662. if (maxfreq == tmds->tmds_pll[i].freq) {
  663. tmds->tmds_pll[i].freq = 0xffffffff;
  664. break;
  665. }
  666. }
  667. }
  668. return tmds;
  669. }
  670. union lvds_info {
  671. struct _ATOM_LVDS_INFO info;
  672. struct _ATOM_LVDS_INFO_V12 info_12;
  673. };
  674. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  675. radeon_encoder
  676. *encoder)
  677. {
  678. struct drm_device *dev = encoder->base.dev;
  679. struct radeon_device *rdev = dev->dev_private;
  680. struct radeon_mode_info *mode_info = &rdev->mode_info;
  681. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  682. uint16_t data_offset;
  683. union lvds_info *lvds_info;
  684. uint8_t frev, crev;
  685. struct radeon_encoder_atom_dig *lvds = NULL;
  686. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
  687. &crev, &data_offset);
  688. lvds_info =
  689. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  690. if (lvds_info) {
  691. lvds =
  692. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  693. if (!lvds)
  694. return NULL;
  695. lvds->native_mode.dotclock =
  696. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  697. lvds->native_mode.panel_xres =
  698. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  699. lvds->native_mode.panel_yres =
  700. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  701. lvds->native_mode.hblank =
  702. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  703. lvds->native_mode.hoverplus =
  704. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  705. lvds->native_mode.hsync_width =
  706. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  707. lvds->native_mode.vblank =
  708. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  709. lvds->native_mode.voverplus =
  710. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  711. lvds->native_mode.vsync_width =
  712. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  713. lvds->panel_pwr_delay =
  714. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  715. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  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. struct radeon_encoder_tv_dac *
  745. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  746. {
  747. struct drm_device *dev = encoder->base.dev;
  748. struct radeon_device *rdev = dev->dev_private;
  749. struct radeon_mode_info *mode_info = &rdev->mode_info;
  750. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  751. uint16_t data_offset;
  752. struct _COMPASSIONATE_DATA *dac_info;
  753. uint8_t frev, crev;
  754. uint8_t bg, dac;
  755. struct radeon_encoder_tv_dac *tv_dac = NULL;
  756. atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
  757. dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
  758. if (dac_info) {
  759. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  760. if (!tv_dac)
  761. return NULL;
  762. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  763. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  764. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  765. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  766. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  767. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  768. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  769. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  770. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  771. }
  772. return tv_dac;
  773. }
  774. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  775. {
  776. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  777. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  778. args.ucEnable = enable;
  779. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  780. }
  781. void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
  782. {
  783. ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
  784. int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
  785. args.ucEnable = enable;
  786. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  787. }
  788. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  789. uint32_t eng_clock)
  790. {
  791. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  792. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  793. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  794. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  795. }
  796. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  797. uint32_t mem_clock)
  798. {
  799. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  800. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  801. if (rdev->flags & RADEON_IS_IGP)
  802. return;
  803. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  804. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  805. }
  806. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  807. {
  808. struct radeon_device *rdev = dev->dev_private;
  809. uint32_t bios_2_scratch, bios_6_scratch;
  810. if (rdev->family >= CHIP_R600) {
  811. bios_2_scratch = RREG32(R600_BIOS_0_SCRATCH);
  812. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  813. } else {
  814. bios_2_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  815. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  816. }
  817. /* let the bios control the backlight */
  818. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  819. /* tell the bios not to handle mode switching */
  820. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  821. if (rdev->family >= CHIP_R600) {
  822. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  823. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  824. } else {
  825. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  826. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  827. }
  828. }
  829. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  830. {
  831. struct drm_device *dev = encoder->dev;
  832. struct radeon_device *rdev = dev->dev_private;
  833. uint32_t bios_6_scratch;
  834. if (rdev->family >= CHIP_R600)
  835. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  836. else
  837. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  838. if (lock)
  839. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  840. else
  841. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  842. if (rdev->family >= CHIP_R600)
  843. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  844. else
  845. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  846. }
  847. /* at some point we may want to break this out into individual functions */
  848. void
  849. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  850. struct drm_encoder *encoder,
  851. bool connected)
  852. {
  853. struct drm_device *dev = connector->dev;
  854. struct radeon_device *rdev = dev->dev_private;
  855. struct radeon_connector *radeon_connector =
  856. to_radeon_connector(connector);
  857. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  858. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  859. if (rdev->family >= CHIP_R600) {
  860. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  861. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  862. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  863. } else {
  864. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  865. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  866. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  867. }
  868. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  869. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  870. if (connected) {
  871. DRM_DEBUG("TV1 connected\n");
  872. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  873. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  874. } else {
  875. DRM_DEBUG("TV1 disconnected\n");
  876. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  877. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  878. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  879. }
  880. }
  881. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  882. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  883. if (connected) {
  884. DRM_DEBUG("CV connected\n");
  885. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  886. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  887. } else {
  888. DRM_DEBUG("CV disconnected\n");
  889. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  890. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  891. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  892. }
  893. }
  894. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  895. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  896. if (connected) {
  897. DRM_DEBUG("LCD1 connected\n");
  898. bios_0_scratch |= ATOM_S0_LCD1;
  899. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  900. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  901. } else {
  902. DRM_DEBUG("LCD1 disconnected\n");
  903. bios_0_scratch &= ~ATOM_S0_LCD1;
  904. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  905. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  906. }
  907. }
  908. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  909. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  910. if (connected) {
  911. DRM_DEBUG("CRT1 connected\n");
  912. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  913. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  914. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  915. } else {
  916. DRM_DEBUG("CRT1 disconnected\n");
  917. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  918. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  919. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  920. }
  921. }
  922. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  923. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  924. if (connected) {
  925. DRM_DEBUG("CRT2 connected\n");
  926. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  927. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  928. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  929. } else {
  930. DRM_DEBUG("CRT2 disconnected\n");
  931. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  932. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  933. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  934. }
  935. }
  936. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  937. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  938. if (connected) {
  939. DRM_DEBUG("DFP1 connected\n");
  940. bios_0_scratch |= ATOM_S0_DFP1;
  941. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  942. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  943. } else {
  944. DRM_DEBUG("DFP1 disconnected\n");
  945. bios_0_scratch &= ~ATOM_S0_DFP1;
  946. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  947. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  948. }
  949. }
  950. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  951. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  952. if (connected) {
  953. DRM_DEBUG("DFP2 connected\n");
  954. bios_0_scratch |= ATOM_S0_DFP2;
  955. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  956. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  957. } else {
  958. DRM_DEBUG("DFP2 disconnected\n");
  959. bios_0_scratch &= ~ATOM_S0_DFP2;
  960. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  961. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  962. }
  963. }
  964. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  965. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  966. if (connected) {
  967. DRM_DEBUG("DFP3 connected\n");
  968. bios_0_scratch |= ATOM_S0_DFP3;
  969. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  970. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  971. } else {
  972. DRM_DEBUG("DFP3 disconnected\n");
  973. bios_0_scratch &= ~ATOM_S0_DFP3;
  974. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  975. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  976. }
  977. }
  978. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  979. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  980. if (connected) {
  981. DRM_DEBUG("DFP4 connected\n");
  982. bios_0_scratch |= ATOM_S0_DFP4;
  983. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  984. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  985. } else {
  986. DRM_DEBUG("DFP4 disconnected\n");
  987. bios_0_scratch &= ~ATOM_S0_DFP4;
  988. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  989. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  990. }
  991. }
  992. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  993. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  994. if (connected) {
  995. DRM_DEBUG("DFP5 connected\n");
  996. bios_0_scratch |= ATOM_S0_DFP5;
  997. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  998. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  999. } else {
  1000. DRM_DEBUG("DFP5 disconnected\n");
  1001. bios_0_scratch &= ~ATOM_S0_DFP5;
  1002. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  1003. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  1004. }
  1005. }
  1006. if (rdev->family >= CHIP_R600) {
  1007. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  1008. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1009. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  1010. } else {
  1011. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  1012. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1013. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  1014. }
  1015. }
  1016. void
  1017. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  1018. {
  1019. struct drm_device *dev = encoder->dev;
  1020. struct radeon_device *rdev = dev->dev_private;
  1021. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1022. uint32_t bios_3_scratch;
  1023. if (rdev->family >= CHIP_R600)
  1024. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  1025. else
  1026. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  1027. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1028. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  1029. bios_3_scratch |= (crtc << 18);
  1030. }
  1031. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1032. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  1033. bios_3_scratch |= (crtc << 24);
  1034. }
  1035. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1036. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  1037. bios_3_scratch |= (crtc << 16);
  1038. }
  1039. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1040. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  1041. bios_3_scratch |= (crtc << 20);
  1042. }
  1043. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1044. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  1045. bios_3_scratch |= (crtc << 17);
  1046. }
  1047. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1048. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  1049. bios_3_scratch |= (crtc << 19);
  1050. }
  1051. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1052. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  1053. bios_3_scratch |= (crtc << 23);
  1054. }
  1055. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1056. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  1057. bios_3_scratch |= (crtc << 25);
  1058. }
  1059. if (rdev->family >= CHIP_R600)
  1060. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  1061. else
  1062. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  1063. }
  1064. void
  1065. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  1066. {
  1067. struct drm_device *dev = encoder->dev;
  1068. struct radeon_device *rdev = dev->dev_private;
  1069. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1070. uint32_t bios_2_scratch;
  1071. if (rdev->family >= CHIP_R600)
  1072. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  1073. else
  1074. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  1075. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  1076. if (on)
  1077. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  1078. else
  1079. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  1080. }
  1081. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  1082. if (on)
  1083. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  1084. else
  1085. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  1086. }
  1087. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  1088. if (on)
  1089. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  1090. else
  1091. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  1092. }
  1093. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  1094. if (on)
  1095. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  1096. else
  1097. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  1098. }
  1099. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  1100. if (on)
  1101. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  1102. else
  1103. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  1104. }
  1105. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  1106. if (on)
  1107. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  1108. else
  1109. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  1110. }
  1111. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  1112. if (on)
  1113. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  1114. else
  1115. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  1116. }
  1117. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  1118. if (on)
  1119. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  1120. else
  1121. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  1122. }
  1123. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  1124. if (on)
  1125. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  1126. else
  1127. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  1128. }
  1129. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  1130. if (on)
  1131. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  1132. else
  1133. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  1134. }
  1135. if (rdev->family >= CHIP_R600)
  1136. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  1137. else
  1138. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  1139. }