radeon_atombios.c 49 KB

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