radeon_atombios.c 51 KB

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