radeon_atombios.c 53 KB

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