radeon_atombios.c 54 KB

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