radeon_atombios.c 53 KB

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