radeon_atombios.c 54 KB

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