radeon_atombios.c 38 KB

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