radeon_atombios.c 54 KB

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