radeon_atombios.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611
  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_enum(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_enum,
  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. uint32_t igp_lane_info,
  47. uint16_t connector_object_id,
  48. struct radeon_hpd *hpd,
  49. struct radeon_router *router);
  50. /* from radeon_legacy_encoder.c */
  51. extern void
  52. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  53. uint32_t supported_device);
  54. union atom_supported_devices {
  55. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  56. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  57. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  58. };
  59. static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  60. uint8_t id)
  61. {
  62. struct atom_context *ctx = rdev->mode_info.atom_context;
  63. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  64. struct radeon_i2c_bus_rec i2c;
  65. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  66. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  67. uint16_t data_offset, size;
  68. int i, num_indices;
  69. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  70. i2c.valid = false;
  71. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  72. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  73. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  74. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  75. for (i = 0; i < num_indices; i++) {
  76. gpio = &i2c_info->asGPIO_Info[i];
  77. if (gpio->sucI2cId.ucAccess == id) {
  78. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  79. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  80. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  81. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  82. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  83. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  84. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  85. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  86. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  87. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  88. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  89. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  90. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  91. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  92. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  93. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  94. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  95. i2c.hw_capable = true;
  96. else
  97. i2c.hw_capable = false;
  98. if (gpio->sucI2cId.ucAccess == 0xa0)
  99. i2c.mm_i2c = true;
  100. else
  101. i2c.mm_i2c = false;
  102. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  103. if (i2c.mask_clk_reg)
  104. i2c.valid = true;
  105. break;
  106. }
  107. }
  108. }
  109. return i2c;
  110. }
  111. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  112. {
  113. struct atom_context *ctx = rdev->mode_info.atom_context;
  114. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  115. struct radeon_i2c_bus_rec i2c;
  116. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  117. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  118. uint16_t data_offset, size;
  119. int i, num_indices;
  120. char stmp[32];
  121. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  122. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  123. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  124. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  125. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  126. for (i = 0; i < num_indices; i++) {
  127. gpio = &i2c_info->asGPIO_Info[i];
  128. i2c.valid = false;
  129. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  130. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  131. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  132. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  133. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  134. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  135. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  136. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  137. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  138. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  139. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  140. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  141. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  142. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  143. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  144. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  145. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  146. i2c.hw_capable = true;
  147. else
  148. i2c.hw_capable = false;
  149. if (gpio->sucI2cId.ucAccess == 0xa0)
  150. i2c.mm_i2c = true;
  151. else
  152. i2c.mm_i2c = false;
  153. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  154. if (i2c.mask_clk_reg) {
  155. i2c.valid = true;
  156. sprintf(stmp, "0x%x", i2c.i2c_id);
  157. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  158. }
  159. }
  160. }
  161. }
  162. static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  163. u8 id)
  164. {
  165. struct atom_context *ctx = rdev->mode_info.atom_context;
  166. struct radeon_gpio_rec gpio;
  167. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  168. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  169. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  170. u16 data_offset, size;
  171. int i, num_indices;
  172. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  173. gpio.valid = false;
  174. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  175. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  176. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  177. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  178. for (i = 0; i < num_indices; i++) {
  179. pin = &gpio_info->asGPIO_Pin[i];
  180. if (id == pin->ucGPIO_ID) {
  181. gpio.id = pin->ucGPIO_ID;
  182. gpio.reg = pin->usGpioPin_AIndex * 4;
  183. gpio.mask = (1 << pin->ucGpioPinBitShift);
  184. gpio.valid = true;
  185. break;
  186. }
  187. }
  188. }
  189. return gpio;
  190. }
  191. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  192. struct radeon_gpio_rec *gpio)
  193. {
  194. struct radeon_hpd hpd;
  195. u32 reg;
  196. memset(&hpd, 0, sizeof(struct radeon_hpd));
  197. if (ASIC_IS_DCE4(rdev))
  198. reg = EVERGREEN_DC_GPIO_HPD_A;
  199. else
  200. reg = AVIVO_DC_GPIO_HPD_A;
  201. hpd.gpio = *gpio;
  202. if (gpio->reg == reg) {
  203. switch(gpio->mask) {
  204. case (1 << 0):
  205. hpd.hpd = RADEON_HPD_1;
  206. break;
  207. case (1 << 8):
  208. hpd.hpd = RADEON_HPD_2;
  209. break;
  210. case (1 << 16):
  211. hpd.hpd = RADEON_HPD_3;
  212. break;
  213. case (1 << 24):
  214. hpd.hpd = RADEON_HPD_4;
  215. break;
  216. case (1 << 26):
  217. hpd.hpd = RADEON_HPD_5;
  218. break;
  219. case (1 << 28):
  220. hpd.hpd = RADEON_HPD_6;
  221. break;
  222. default:
  223. hpd.hpd = RADEON_HPD_NONE;
  224. break;
  225. }
  226. } else
  227. hpd.hpd = RADEON_HPD_NONE;
  228. return hpd;
  229. }
  230. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  231. uint32_t supported_device,
  232. int *connector_type,
  233. struct radeon_i2c_bus_rec *i2c_bus,
  234. uint16_t *line_mux,
  235. struct radeon_hpd *hpd)
  236. {
  237. struct radeon_device *rdev = dev->dev_private;
  238. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  239. if ((dev->pdev->device == 0x791e) &&
  240. (dev->pdev->subsystem_vendor == 0x1043) &&
  241. (dev->pdev->subsystem_device == 0x826d)) {
  242. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  243. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  244. *connector_type = DRM_MODE_CONNECTOR_DVID;
  245. }
  246. /* Asrock RS600 board lists the DVI port as HDMI */
  247. if ((dev->pdev->device == 0x7941) &&
  248. (dev->pdev->subsystem_vendor == 0x1849) &&
  249. (dev->pdev->subsystem_device == 0x7941)) {
  250. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  251. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  252. *connector_type = DRM_MODE_CONNECTOR_DVID;
  253. }
  254. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  255. if ((dev->pdev->device == 0x7941) &&
  256. (dev->pdev->subsystem_vendor == 0x147b) &&
  257. (dev->pdev->subsystem_device == 0x2412)) {
  258. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  259. return false;
  260. }
  261. /* Falcon NW laptop lists vga ddc line for LVDS */
  262. if ((dev->pdev->device == 0x5653) &&
  263. (dev->pdev->subsystem_vendor == 0x1462) &&
  264. (dev->pdev->subsystem_device == 0x0291)) {
  265. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  266. i2c_bus->valid = false;
  267. *line_mux = 53;
  268. }
  269. }
  270. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  271. if ((dev->pdev->device == 0x7146) &&
  272. (dev->pdev->subsystem_vendor == 0x17af) &&
  273. (dev->pdev->subsystem_device == 0x2058)) {
  274. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  275. return false;
  276. }
  277. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  278. if ((dev->pdev->device == 0x7142) &&
  279. (dev->pdev->subsystem_vendor == 0x1458) &&
  280. (dev->pdev->subsystem_device == 0x2134)) {
  281. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  282. return false;
  283. }
  284. /* Funky macbooks */
  285. if ((dev->pdev->device == 0x71C5) &&
  286. (dev->pdev->subsystem_vendor == 0x106b) &&
  287. (dev->pdev->subsystem_device == 0x0080)) {
  288. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  289. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  290. return false;
  291. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  292. *line_mux = 0x90;
  293. }
  294. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  295. if ((dev->pdev->device == 0x9598) &&
  296. (dev->pdev->subsystem_vendor == 0x1043) &&
  297. (dev->pdev->subsystem_device == 0x01da)) {
  298. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  299. *connector_type = DRM_MODE_CONNECTOR_DVII;
  300. }
  301. }
  302. /* ASUS HD 3600 board lists the DVI port as HDMI */
  303. if ((dev->pdev->device == 0x9598) &&
  304. (dev->pdev->subsystem_vendor == 0x1043) &&
  305. (dev->pdev->subsystem_device == 0x01e4)) {
  306. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  307. *connector_type = DRM_MODE_CONNECTOR_DVII;
  308. }
  309. }
  310. /* ASUS HD 3450 board lists the DVI port as HDMI */
  311. if ((dev->pdev->device == 0x95C5) &&
  312. (dev->pdev->subsystem_vendor == 0x1043) &&
  313. (dev->pdev->subsystem_device == 0x01e2)) {
  314. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  315. *connector_type = DRM_MODE_CONNECTOR_DVII;
  316. }
  317. }
  318. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  319. * HDMI + VGA reporting as HDMI
  320. */
  321. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  322. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  323. *connector_type = DRM_MODE_CONNECTOR_VGA;
  324. *line_mux = 0;
  325. }
  326. }
  327. /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
  328. if ((dev->pdev->device == 0x95c4) &&
  329. (dev->pdev->subsystem_vendor == 0x1025) &&
  330. (dev->pdev->subsystem_device == 0x013c)) {
  331. struct radeon_gpio_rec gpio;
  332. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  333. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  334. gpio = radeon_lookup_gpio(rdev, 6);
  335. *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  336. *connector_type = DRM_MODE_CONNECTOR_DVID;
  337. } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  338. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  339. gpio = radeon_lookup_gpio(rdev, 7);
  340. *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  341. }
  342. }
  343. /* XFX Pine Group device rv730 reports no VGA DDC lines
  344. * even though they are wired up to record 0x93
  345. */
  346. if ((dev->pdev->device == 0x9498) &&
  347. (dev->pdev->subsystem_vendor == 0x1682) &&
  348. (dev->pdev->subsystem_device == 0x2452)) {
  349. struct radeon_device *rdev = dev->dev_private;
  350. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  351. }
  352. return true;
  353. }
  354. const int supported_devices_connector_convert[] = {
  355. DRM_MODE_CONNECTOR_Unknown,
  356. DRM_MODE_CONNECTOR_VGA,
  357. DRM_MODE_CONNECTOR_DVII,
  358. DRM_MODE_CONNECTOR_DVID,
  359. DRM_MODE_CONNECTOR_DVIA,
  360. DRM_MODE_CONNECTOR_SVIDEO,
  361. DRM_MODE_CONNECTOR_Composite,
  362. DRM_MODE_CONNECTOR_LVDS,
  363. DRM_MODE_CONNECTOR_Unknown,
  364. DRM_MODE_CONNECTOR_Unknown,
  365. DRM_MODE_CONNECTOR_HDMIA,
  366. DRM_MODE_CONNECTOR_HDMIB,
  367. DRM_MODE_CONNECTOR_Unknown,
  368. DRM_MODE_CONNECTOR_Unknown,
  369. DRM_MODE_CONNECTOR_9PinDIN,
  370. DRM_MODE_CONNECTOR_DisplayPort
  371. };
  372. const uint16_t supported_devices_connector_object_id_convert[] = {
  373. CONNECTOR_OBJECT_ID_NONE,
  374. CONNECTOR_OBJECT_ID_VGA,
  375. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  376. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  377. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  378. CONNECTOR_OBJECT_ID_COMPOSITE,
  379. CONNECTOR_OBJECT_ID_SVIDEO,
  380. CONNECTOR_OBJECT_ID_LVDS,
  381. CONNECTOR_OBJECT_ID_9PIN_DIN,
  382. CONNECTOR_OBJECT_ID_9PIN_DIN,
  383. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  384. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  385. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  386. CONNECTOR_OBJECT_ID_SVIDEO
  387. };
  388. const int object_connector_convert[] = {
  389. DRM_MODE_CONNECTOR_Unknown,
  390. DRM_MODE_CONNECTOR_DVII,
  391. DRM_MODE_CONNECTOR_DVII,
  392. DRM_MODE_CONNECTOR_DVID,
  393. DRM_MODE_CONNECTOR_DVID,
  394. DRM_MODE_CONNECTOR_VGA,
  395. DRM_MODE_CONNECTOR_Composite,
  396. DRM_MODE_CONNECTOR_SVIDEO,
  397. DRM_MODE_CONNECTOR_Unknown,
  398. DRM_MODE_CONNECTOR_Unknown,
  399. DRM_MODE_CONNECTOR_9PinDIN,
  400. DRM_MODE_CONNECTOR_Unknown,
  401. DRM_MODE_CONNECTOR_HDMIA,
  402. DRM_MODE_CONNECTOR_HDMIB,
  403. DRM_MODE_CONNECTOR_LVDS,
  404. DRM_MODE_CONNECTOR_9PinDIN,
  405. DRM_MODE_CONNECTOR_Unknown,
  406. DRM_MODE_CONNECTOR_Unknown,
  407. DRM_MODE_CONNECTOR_Unknown,
  408. DRM_MODE_CONNECTOR_DisplayPort,
  409. DRM_MODE_CONNECTOR_eDP,
  410. DRM_MODE_CONNECTOR_Unknown
  411. };
  412. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  413. {
  414. struct radeon_device *rdev = dev->dev_private;
  415. struct radeon_mode_info *mode_info = &rdev->mode_info;
  416. struct atom_context *ctx = mode_info->atom_context;
  417. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  418. u16 size, data_offset;
  419. u8 frev, crev;
  420. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  421. ATOM_OBJECT_TABLE *router_obj;
  422. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  423. ATOM_OBJECT_HEADER *obj_header;
  424. int i, j, k, path_size, device_support;
  425. int connector_type;
  426. u16 igp_lane_info, conn_id, connector_object_id;
  427. struct radeon_i2c_bus_rec ddc_bus;
  428. struct radeon_router router;
  429. struct radeon_gpio_rec gpio;
  430. struct radeon_hpd hpd;
  431. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  432. return false;
  433. if (crev < 2)
  434. return false;
  435. router.valid = false;
  436. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  437. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  438. (ctx->bios + data_offset +
  439. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  440. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  441. (ctx->bios + data_offset +
  442. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  443. router_obj = (ATOM_OBJECT_TABLE *)
  444. (ctx->bios + data_offset +
  445. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  446. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  447. path_size = 0;
  448. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  449. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  450. ATOM_DISPLAY_OBJECT_PATH *path;
  451. addr += path_size;
  452. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  453. path_size += le16_to_cpu(path->usSize);
  454. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  455. uint8_t con_obj_id, con_obj_num, con_obj_type;
  456. con_obj_id =
  457. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  458. >> OBJECT_ID_SHIFT;
  459. con_obj_num =
  460. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  461. >> ENUM_ID_SHIFT;
  462. con_obj_type =
  463. (le16_to_cpu(path->usConnObjectId) &
  464. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  465. /* TODO CV support */
  466. if (le16_to_cpu(path->usDeviceTag) ==
  467. ATOM_DEVICE_CV_SUPPORT)
  468. continue;
  469. /* IGP chips */
  470. if ((rdev->flags & RADEON_IS_IGP) &&
  471. (con_obj_id ==
  472. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  473. uint16_t igp_offset = 0;
  474. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  475. index =
  476. GetIndexIntoMasterTable(DATA,
  477. IntegratedSystemInfo);
  478. if (atom_parse_data_header(ctx, index, &size, &frev,
  479. &crev, &igp_offset)) {
  480. if (crev >= 2) {
  481. igp_obj =
  482. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  483. *) (ctx->bios + igp_offset);
  484. if (igp_obj) {
  485. uint32_t slot_config, ct;
  486. if (con_obj_num == 1)
  487. slot_config =
  488. igp_obj->
  489. ulDDISlot1Config;
  490. else
  491. slot_config =
  492. igp_obj->
  493. ulDDISlot2Config;
  494. ct = (slot_config >> 16) & 0xff;
  495. connector_type =
  496. object_connector_convert
  497. [ct];
  498. connector_object_id = ct;
  499. igp_lane_info =
  500. slot_config & 0xffff;
  501. } else
  502. continue;
  503. } else
  504. continue;
  505. } else {
  506. igp_lane_info = 0;
  507. connector_type =
  508. object_connector_convert[con_obj_id];
  509. connector_object_id = con_obj_id;
  510. }
  511. } else {
  512. igp_lane_info = 0;
  513. connector_type =
  514. object_connector_convert[con_obj_id];
  515. connector_object_id = con_obj_id;
  516. }
  517. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  518. continue;
  519. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  520. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  521. grph_obj_id =
  522. (le16_to_cpu(path->usGraphicObjIds[j]) &
  523. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  524. grph_obj_num =
  525. (le16_to_cpu(path->usGraphicObjIds[j]) &
  526. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  527. grph_obj_type =
  528. (le16_to_cpu(path->usGraphicObjIds[j]) &
  529. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  530. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  531. u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
  532. radeon_add_atom_encoder(dev,
  533. encoder_obj,
  534. le16_to_cpu
  535. (path->
  536. usDeviceTag));
  537. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  538. router.valid = false;
  539. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  540. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
  541. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  542. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  543. (ctx->bios + data_offset +
  544. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  545. ATOM_I2C_RECORD *i2c_record;
  546. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  547. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  548. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  549. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  550. (ctx->bios + data_offset +
  551. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  552. int enum_id;
  553. router.router_id = router_obj_id;
  554. for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
  555. enum_id++) {
  556. if (le16_to_cpu(path->usConnObjectId) ==
  557. le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
  558. break;
  559. }
  560. while (record->ucRecordType > 0 &&
  561. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  562. switch (record->ucRecordType) {
  563. case ATOM_I2C_RECORD_TYPE:
  564. i2c_record =
  565. (ATOM_I2C_RECORD *)
  566. record;
  567. i2c_config =
  568. (ATOM_I2C_ID_CONFIG_ACCESS *)
  569. &i2c_record->sucI2cId;
  570. router.i2c_info =
  571. radeon_lookup_i2c_gpio(rdev,
  572. i2c_config->
  573. ucAccess);
  574. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  575. break;
  576. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  577. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  578. record;
  579. router.valid = true;
  580. router.mux_type = ddc_path->ucMuxType;
  581. router.mux_control_pin = ddc_path->ucMuxControlPin;
  582. router.mux_state = ddc_path->ucMuxState[enum_id];
  583. break;
  584. }
  585. record = (ATOM_COMMON_RECORD_HEADER *)
  586. ((char *)record + record->ucRecordSize);
  587. }
  588. }
  589. }
  590. }
  591. }
  592. /* look up gpio for ddc, hpd */
  593. ddc_bus.valid = false;
  594. hpd.hpd = RADEON_HPD_NONE;
  595. if ((le16_to_cpu(path->usDeviceTag) &
  596. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  597. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  598. if (le16_to_cpu(path->usConnObjectId) ==
  599. le16_to_cpu(con_obj->asObjects[j].
  600. usObjectID)) {
  601. ATOM_COMMON_RECORD_HEADER
  602. *record =
  603. (ATOM_COMMON_RECORD_HEADER
  604. *)
  605. (ctx->bios + data_offset +
  606. le16_to_cpu(con_obj->
  607. asObjects[j].
  608. usRecordOffset));
  609. ATOM_I2C_RECORD *i2c_record;
  610. ATOM_HPD_INT_RECORD *hpd_record;
  611. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  612. while (record->ucRecordType > 0
  613. && record->
  614. ucRecordType <=
  615. ATOM_MAX_OBJECT_RECORD_NUMBER) {
  616. switch (record->ucRecordType) {
  617. case ATOM_I2C_RECORD_TYPE:
  618. i2c_record =
  619. (ATOM_I2C_RECORD *)
  620. record;
  621. i2c_config =
  622. (ATOM_I2C_ID_CONFIG_ACCESS *)
  623. &i2c_record->sucI2cId;
  624. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  625. i2c_config->
  626. ucAccess);
  627. break;
  628. case ATOM_HPD_INT_RECORD_TYPE:
  629. hpd_record =
  630. (ATOM_HPD_INT_RECORD *)
  631. record;
  632. gpio = radeon_lookup_gpio(rdev,
  633. hpd_record->ucHPDIntGPIOID);
  634. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  635. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  636. break;
  637. }
  638. record =
  639. (ATOM_COMMON_RECORD_HEADER
  640. *) ((char *)record
  641. +
  642. record->
  643. ucRecordSize);
  644. }
  645. break;
  646. }
  647. }
  648. }
  649. /* needed for aux chan transactions */
  650. ddc_bus.hpd = hpd.hpd;
  651. conn_id = le16_to_cpu(path->usConnObjectId);
  652. if (!radeon_atom_apply_quirks
  653. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  654. &ddc_bus, &conn_id, &hpd))
  655. continue;
  656. radeon_add_atom_connector(dev,
  657. conn_id,
  658. le16_to_cpu(path->
  659. usDeviceTag),
  660. connector_type, &ddc_bus,
  661. igp_lane_info,
  662. connector_object_id,
  663. &hpd,
  664. &router);
  665. }
  666. }
  667. radeon_link_encoder_connector(dev);
  668. return true;
  669. }
  670. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  671. int connector_type,
  672. uint16_t devices)
  673. {
  674. struct radeon_device *rdev = dev->dev_private;
  675. if (rdev->flags & RADEON_IS_IGP) {
  676. return supported_devices_connector_object_id_convert
  677. [connector_type];
  678. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  679. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  680. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  681. struct radeon_mode_info *mode_info = &rdev->mode_info;
  682. struct atom_context *ctx = mode_info->atom_context;
  683. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  684. uint16_t size, data_offset;
  685. uint8_t frev, crev;
  686. ATOM_XTMDS_INFO *xtmds;
  687. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  688. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  689. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  690. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  691. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  692. else
  693. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  694. } else {
  695. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  696. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  697. else
  698. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  699. }
  700. } else
  701. return supported_devices_connector_object_id_convert
  702. [connector_type];
  703. } else {
  704. return supported_devices_connector_object_id_convert
  705. [connector_type];
  706. }
  707. }
  708. struct bios_connector {
  709. bool valid;
  710. uint16_t line_mux;
  711. uint16_t devices;
  712. int connector_type;
  713. struct radeon_i2c_bus_rec ddc_bus;
  714. struct radeon_hpd hpd;
  715. };
  716. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  717. drm_device
  718. *dev)
  719. {
  720. struct radeon_device *rdev = dev->dev_private;
  721. struct radeon_mode_info *mode_info = &rdev->mode_info;
  722. struct atom_context *ctx = mode_info->atom_context;
  723. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  724. uint16_t size, data_offset;
  725. uint8_t frev, crev;
  726. uint16_t device_support;
  727. uint8_t dac;
  728. union atom_supported_devices *supported_devices;
  729. int i, j, max_device;
  730. struct bios_connector *bios_connectors;
  731. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  732. struct radeon_router router;
  733. router.valid = false;
  734. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  735. if (!bios_connectors)
  736. return false;
  737. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  738. &data_offset)) {
  739. kfree(bios_connectors);
  740. return false;
  741. }
  742. supported_devices =
  743. (union atom_supported_devices *)(ctx->bios + data_offset);
  744. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  745. if (frev > 1)
  746. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  747. else
  748. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  749. for (i = 0; i < max_device; i++) {
  750. ATOM_CONNECTOR_INFO_I2C ci =
  751. supported_devices->info.asConnInfo[i];
  752. bios_connectors[i].valid = false;
  753. if (!(device_support & (1 << i))) {
  754. continue;
  755. }
  756. if (i == ATOM_DEVICE_CV_INDEX) {
  757. DRM_DEBUG_KMS("Skipping Component Video\n");
  758. continue;
  759. }
  760. bios_connectors[i].connector_type =
  761. supported_devices_connector_convert[ci.sucConnectorInfo.
  762. sbfAccess.
  763. bfConnectorType];
  764. if (bios_connectors[i].connector_type ==
  765. DRM_MODE_CONNECTOR_Unknown)
  766. continue;
  767. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  768. bios_connectors[i].line_mux =
  769. ci.sucI2cId.ucAccess;
  770. /* give tv unique connector ids */
  771. if (i == ATOM_DEVICE_TV1_INDEX) {
  772. bios_connectors[i].ddc_bus.valid = false;
  773. bios_connectors[i].line_mux = 50;
  774. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  775. bios_connectors[i].ddc_bus.valid = false;
  776. bios_connectors[i].line_mux = 51;
  777. } else if (i == ATOM_DEVICE_CV_INDEX) {
  778. bios_connectors[i].ddc_bus.valid = false;
  779. bios_connectors[i].line_mux = 52;
  780. } else
  781. bios_connectors[i].ddc_bus =
  782. radeon_lookup_i2c_gpio(rdev,
  783. bios_connectors[i].line_mux);
  784. if ((crev > 1) && (frev > 1)) {
  785. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  786. switch (isb) {
  787. case 0x4:
  788. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  789. break;
  790. case 0xa:
  791. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  792. break;
  793. default:
  794. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  795. break;
  796. }
  797. } else {
  798. if (i == ATOM_DEVICE_DFP1_INDEX)
  799. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  800. else if (i == ATOM_DEVICE_DFP2_INDEX)
  801. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  802. else
  803. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  804. }
  805. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  806. * shared with a DVI port, we'll pick up the DVI connector when we
  807. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  808. */
  809. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  810. bios_connectors[i].connector_type =
  811. DRM_MODE_CONNECTOR_VGA;
  812. if (!radeon_atom_apply_quirks
  813. (dev, (1 << i), &bios_connectors[i].connector_type,
  814. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  815. &bios_connectors[i].hpd))
  816. continue;
  817. bios_connectors[i].valid = true;
  818. bios_connectors[i].devices = (1 << i);
  819. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  820. radeon_add_atom_encoder(dev,
  821. radeon_get_encoder_enum(dev,
  822. (1 << i),
  823. dac),
  824. (1 << i));
  825. else
  826. radeon_add_legacy_encoder(dev,
  827. radeon_get_encoder_enum(dev,
  828. (1 << i),
  829. dac),
  830. (1 << i));
  831. }
  832. /* combine shared connectors */
  833. for (i = 0; i < max_device; i++) {
  834. if (bios_connectors[i].valid) {
  835. for (j = 0; j < max_device; j++) {
  836. if (bios_connectors[j].valid && (i != j)) {
  837. if (bios_connectors[i].line_mux ==
  838. bios_connectors[j].line_mux) {
  839. /* make sure not to combine LVDS */
  840. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  841. bios_connectors[i].line_mux = 53;
  842. bios_connectors[i].ddc_bus.valid = false;
  843. continue;
  844. }
  845. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  846. bios_connectors[j].line_mux = 53;
  847. bios_connectors[j].ddc_bus.valid = false;
  848. continue;
  849. }
  850. /* combine analog and digital for DVI-I */
  851. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  852. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  853. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  854. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  855. bios_connectors[i].devices |=
  856. bios_connectors[j].devices;
  857. bios_connectors[i].connector_type =
  858. DRM_MODE_CONNECTOR_DVII;
  859. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  860. bios_connectors[i].hpd =
  861. bios_connectors[j].hpd;
  862. bios_connectors[j].valid = false;
  863. }
  864. }
  865. }
  866. }
  867. }
  868. }
  869. /* add the connectors */
  870. for (i = 0; i < max_device; i++) {
  871. if (bios_connectors[i].valid) {
  872. uint16_t connector_object_id =
  873. atombios_get_connector_object_id(dev,
  874. bios_connectors[i].connector_type,
  875. bios_connectors[i].devices);
  876. radeon_add_atom_connector(dev,
  877. bios_connectors[i].line_mux,
  878. bios_connectors[i].devices,
  879. bios_connectors[i].
  880. connector_type,
  881. &bios_connectors[i].ddc_bus,
  882. 0,
  883. connector_object_id,
  884. &bios_connectors[i].hpd,
  885. &router);
  886. }
  887. }
  888. radeon_link_encoder_connector(dev);
  889. kfree(bios_connectors);
  890. return true;
  891. }
  892. union firmware_info {
  893. ATOM_FIRMWARE_INFO info;
  894. ATOM_FIRMWARE_INFO_V1_2 info_12;
  895. ATOM_FIRMWARE_INFO_V1_3 info_13;
  896. ATOM_FIRMWARE_INFO_V1_4 info_14;
  897. ATOM_FIRMWARE_INFO_V2_1 info_21;
  898. };
  899. bool radeon_atom_get_clock_info(struct drm_device *dev)
  900. {
  901. struct radeon_device *rdev = dev->dev_private;
  902. struct radeon_mode_info *mode_info = &rdev->mode_info;
  903. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  904. union firmware_info *firmware_info;
  905. uint8_t frev, crev;
  906. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  907. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  908. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  909. struct radeon_pll *spll = &rdev->clock.spll;
  910. struct radeon_pll *mpll = &rdev->clock.mpll;
  911. uint16_t data_offset;
  912. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  913. &frev, &crev, &data_offset)) {
  914. firmware_info =
  915. (union firmware_info *)(mode_info->atom_context->bios +
  916. data_offset);
  917. /* pixel clocks */
  918. p1pll->reference_freq =
  919. le16_to_cpu(firmware_info->info.usReferenceClock);
  920. p1pll->reference_div = 0;
  921. if (crev < 2)
  922. p1pll->pll_out_min =
  923. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  924. else
  925. p1pll->pll_out_min =
  926. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  927. p1pll->pll_out_max =
  928. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  929. if (crev >= 4) {
  930. p1pll->lcd_pll_out_min =
  931. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  932. if (p1pll->lcd_pll_out_min == 0)
  933. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  934. p1pll->lcd_pll_out_max =
  935. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  936. if (p1pll->lcd_pll_out_max == 0)
  937. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  938. } else {
  939. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  940. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  941. }
  942. if (p1pll->pll_out_min == 0) {
  943. if (ASIC_IS_AVIVO(rdev))
  944. p1pll->pll_out_min = 64800;
  945. else
  946. p1pll->pll_out_min = 20000;
  947. } else if (p1pll->pll_out_min > 64800) {
  948. /* Limiting the pll output range is a good thing generally as
  949. * it limits the number of possible pll combinations for a given
  950. * frequency presumably to the ones that work best on each card.
  951. * However, certain duallink DVI monitors seem to like
  952. * pll combinations that would be limited by this at least on
  953. * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
  954. * family.
  955. */
  956. if (!radeon_new_pll)
  957. p1pll->pll_out_min = 64800;
  958. }
  959. p1pll->pll_in_min =
  960. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  961. p1pll->pll_in_max =
  962. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  963. *p2pll = *p1pll;
  964. /* system clock */
  965. spll->reference_freq =
  966. le16_to_cpu(firmware_info->info.usReferenceClock);
  967. spll->reference_div = 0;
  968. spll->pll_out_min =
  969. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  970. spll->pll_out_max =
  971. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  972. /* ??? */
  973. if (spll->pll_out_min == 0) {
  974. if (ASIC_IS_AVIVO(rdev))
  975. spll->pll_out_min = 64800;
  976. else
  977. spll->pll_out_min = 20000;
  978. }
  979. spll->pll_in_min =
  980. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  981. spll->pll_in_max =
  982. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  983. /* memory clock */
  984. mpll->reference_freq =
  985. le16_to_cpu(firmware_info->info.usReferenceClock);
  986. mpll->reference_div = 0;
  987. mpll->pll_out_min =
  988. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  989. mpll->pll_out_max =
  990. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  991. /* ??? */
  992. if (mpll->pll_out_min == 0) {
  993. if (ASIC_IS_AVIVO(rdev))
  994. mpll->pll_out_min = 64800;
  995. else
  996. mpll->pll_out_min = 20000;
  997. }
  998. mpll->pll_in_min =
  999. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1000. mpll->pll_in_max =
  1001. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1002. rdev->clock.default_sclk =
  1003. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1004. rdev->clock.default_mclk =
  1005. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1006. if (ASIC_IS_DCE4(rdev)) {
  1007. rdev->clock.default_dispclk =
  1008. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1009. if (rdev->clock.default_dispclk == 0)
  1010. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1011. rdev->clock.dp_extclk =
  1012. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1013. }
  1014. *dcpll = *p1pll;
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. union igp_info {
  1020. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1021. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1022. };
  1023. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1024. {
  1025. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1026. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1027. union igp_info *igp_info;
  1028. u8 frev, crev;
  1029. u16 data_offset;
  1030. /* sideport is AMD only */
  1031. if (rdev->family == CHIP_RS600)
  1032. return false;
  1033. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1034. &frev, &crev, &data_offset)) {
  1035. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1036. data_offset);
  1037. switch (crev) {
  1038. case 1:
  1039. if (igp_info->info.ulBootUpMemoryClock)
  1040. return true;
  1041. break;
  1042. case 2:
  1043. if (igp_info->info_2.ulBootUpSidePortClock)
  1044. return true;
  1045. break;
  1046. default:
  1047. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1048. break;
  1049. }
  1050. }
  1051. return false;
  1052. }
  1053. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1054. struct radeon_encoder_int_tmds *tmds)
  1055. {
  1056. struct drm_device *dev = encoder->base.dev;
  1057. struct radeon_device *rdev = dev->dev_private;
  1058. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1059. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1060. uint16_t data_offset;
  1061. struct _ATOM_TMDS_INFO *tmds_info;
  1062. uint8_t frev, crev;
  1063. uint16_t maxfreq;
  1064. int i;
  1065. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1066. &frev, &crev, &data_offset)) {
  1067. tmds_info =
  1068. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1069. data_offset);
  1070. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1071. for (i = 0; i < 4; i++) {
  1072. tmds->tmds_pll[i].freq =
  1073. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1074. tmds->tmds_pll[i].value =
  1075. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1076. tmds->tmds_pll[i].value |=
  1077. (tmds_info->asMiscInfo[i].
  1078. ucPLL_VCO_Gain & 0x3f) << 6;
  1079. tmds->tmds_pll[i].value |=
  1080. (tmds_info->asMiscInfo[i].
  1081. ucPLL_DutyCycle & 0xf) << 12;
  1082. tmds->tmds_pll[i].value |=
  1083. (tmds_info->asMiscInfo[i].
  1084. ucPLL_VoltageSwing & 0xf) << 16;
  1085. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1086. tmds->tmds_pll[i].freq,
  1087. tmds->tmds_pll[i].value);
  1088. if (maxfreq == tmds->tmds_pll[i].freq) {
  1089. tmds->tmds_pll[i].freq = 0xffffffff;
  1090. break;
  1091. }
  1092. }
  1093. return true;
  1094. }
  1095. return false;
  1096. }
  1097. static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
  1098. radeon_encoder
  1099. *encoder,
  1100. int id)
  1101. {
  1102. struct drm_device *dev = encoder->base.dev;
  1103. struct radeon_device *rdev = dev->dev_private;
  1104. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1105. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1106. uint16_t data_offset;
  1107. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1108. uint8_t frev, crev;
  1109. struct radeon_atom_ss *ss = NULL;
  1110. int i;
  1111. if (id > ATOM_MAX_SS_ENTRY)
  1112. return NULL;
  1113. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1114. &frev, &crev, &data_offset)) {
  1115. ss_info =
  1116. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1117. ss =
  1118. kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
  1119. if (!ss)
  1120. return NULL;
  1121. for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
  1122. if (ss_info->asSS_Info[i].ucSS_Id == id) {
  1123. ss->percentage =
  1124. le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
  1125. ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
  1126. ss->step = ss_info->asSS_Info[i].ucSS_Step;
  1127. ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
  1128. ss->range = ss_info->asSS_Info[i].ucSS_Range;
  1129. ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
  1130. break;
  1131. }
  1132. }
  1133. }
  1134. return ss;
  1135. }
  1136. union lvds_info {
  1137. struct _ATOM_LVDS_INFO info;
  1138. struct _ATOM_LVDS_INFO_V12 info_12;
  1139. };
  1140. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1141. radeon_encoder
  1142. *encoder)
  1143. {
  1144. struct drm_device *dev = encoder->base.dev;
  1145. struct radeon_device *rdev = dev->dev_private;
  1146. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1147. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1148. uint16_t data_offset, misc;
  1149. union lvds_info *lvds_info;
  1150. uint8_t frev, crev;
  1151. struct radeon_encoder_atom_dig *lvds = NULL;
  1152. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1153. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1154. &frev, &crev, &data_offset)) {
  1155. lvds_info =
  1156. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1157. lvds =
  1158. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1159. if (!lvds)
  1160. return NULL;
  1161. lvds->native_mode.clock =
  1162. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1163. lvds->native_mode.hdisplay =
  1164. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1165. lvds->native_mode.vdisplay =
  1166. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1167. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1168. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1169. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1170. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1171. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1172. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1173. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1174. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1175. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1176. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1177. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1178. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1179. lvds->panel_pwr_delay =
  1180. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1181. lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
  1182. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1183. if (misc & ATOM_VSYNC_POLARITY)
  1184. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1185. if (misc & ATOM_HSYNC_POLARITY)
  1186. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1187. if (misc & ATOM_COMPOSITESYNC)
  1188. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1189. if (misc & ATOM_INTERLACE)
  1190. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1191. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1192. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1193. /* set crtc values */
  1194. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1195. lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
  1196. if (ASIC_IS_AVIVO(rdev)) {
  1197. if (radeon_new_pll == 0)
  1198. lvds->pll_algo = PLL_ALGO_LEGACY;
  1199. else
  1200. lvds->pll_algo = PLL_ALGO_NEW;
  1201. } else {
  1202. if (radeon_new_pll == 1)
  1203. lvds->pll_algo = PLL_ALGO_NEW;
  1204. else
  1205. lvds->pll_algo = PLL_ALGO_LEGACY;
  1206. }
  1207. encoder->native_mode = lvds->native_mode;
  1208. if (encoder_enum == 2)
  1209. lvds->linkb = true;
  1210. else
  1211. lvds->linkb = false;
  1212. }
  1213. return lvds;
  1214. }
  1215. struct radeon_encoder_primary_dac *
  1216. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1217. {
  1218. struct drm_device *dev = encoder->base.dev;
  1219. struct radeon_device *rdev = dev->dev_private;
  1220. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1221. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1222. uint16_t data_offset;
  1223. struct _COMPASSIONATE_DATA *dac_info;
  1224. uint8_t frev, crev;
  1225. uint8_t bg, dac;
  1226. struct radeon_encoder_primary_dac *p_dac = NULL;
  1227. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1228. &frev, &crev, &data_offset)) {
  1229. dac_info = (struct _COMPASSIONATE_DATA *)
  1230. (mode_info->atom_context->bios + data_offset);
  1231. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1232. if (!p_dac)
  1233. return NULL;
  1234. bg = dac_info->ucDAC1_BG_Adjustment;
  1235. dac = dac_info->ucDAC1_DAC_Adjustment;
  1236. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1237. }
  1238. return p_dac;
  1239. }
  1240. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1241. struct drm_display_mode *mode)
  1242. {
  1243. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1244. ATOM_ANALOG_TV_INFO *tv_info;
  1245. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1246. ATOM_DTD_FORMAT *dtd_timings;
  1247. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1248. u8 frev, crev;
  1249. u16 data_offset, misc;
  1250. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1251. &frev, &crev, &data_offset))
  1252. return false;
  1253. switch (crev) {
  1254. case 1:
  1255. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1256. if (index >= MAX_SUPPORTED_TV_TIMING)
  1257. return false;
  1258. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1259. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1260. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1261. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1262. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1263. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1264. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1265. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1266. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1267. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1268. mode->flags = 0;
  1269. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1270. if (misc & ATOM_VSYNC_POLARITY)
  1271. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1272. if (misc & ATOM_HSYNC_POLARITY)
  1273. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1274. if (misc & ATOM_COMPOSITESYNC)
  1275. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1276. if (misc & ATOM_INTERLACE)
  1277. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1278. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1279. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1280. mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1281. if (index == 1) {
  1282. /* PAL timings appear to have wrong values for totals */
  1283. mode->crtc_htotal -= 1;
  1284. mode->crtc_vtotal -= 1;
  1285. }
  1286. break;
  1287. case 2:
  1288. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1289. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1290. return false;
  1291. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1292. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1293. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1294. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1295. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1296. le16_to_cpu(dtd_timings->usHSyncOffset);
  1297. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1298. le16_to_cpu(dtd_timings->usHSyncWidth);
  1299. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1300. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1301. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1302. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1303. le16_to_cpu(dtd_timings->usVSyncOffset);
  1304. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1305. le16_to_cpu(dtd_timings->usVSyncWidth);
  1306. mode->flags = 0;
  1307. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1308. if (misc & ATOM_VSYNC_POLARITY)
  1309. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1310. if (misc & ATOM_HSYNC_POLARITY)
  1311. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1312. if (misc & ATOM_COMPOSITESYNC)
  1313. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1314. if (misc & ATOM_INTERLACE)
  1315. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1316. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1317. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1318. mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
  1319. break;
  1320. }
  1321. return true;
  1322. }
  1323. enum radeon_tv_std
  1324. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1325. {
  1326. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1327. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1328. uint16_t data_offset;
  1329. uint8_t frev, crev;
  1330. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1331. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1332. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1333. &frev, &crev, &data_offset)) {
  1334. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1335. (mode_info->atom_context->bios + data_offset);
  1336. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1337. case ATOM_TV_NTSC:
  1338. tv_std = TV_STD_NTSC;
  1339. DRM_INFO("Default TV standard: NTSC\n");
  1340. break;
  1341. case ATOM_TV_NTSCJ:
  1342. tv_std = TV_STD_NTSC_J;
  1343. DRM_INFO("Default TV standard: NTSC-J\n");
  1344. break;
  1345. case ATOM_TV_PAL:
  1346. tv_std = TV_STD_PAL;
  1347. DRM_INFO("Default TV standard: PAL\n");
  1348. break;
  1349. case ATOM_TV_PALM:
  1350. tv_std = TV_STD_PAL_M;
  1351. DRM_INFO("Default TV standard: PAL-M\n");
  1352. break;
  1353. case ATOM_TV_PALN:
  1354. tv_std = TV_STD_PAL_N;
  1355. DRM_INFO("Default TV standard: PAL-N\n");
  1356. break;
  1357. case ATOM_TV_PALCN:
  1358. tv_std = TV_STD_PAL_CN;
  1359. DRM_INFO("Default TV standard: PAL-CN\n");
  1360. break;
  1361. case ATOM_TV_PAL60:
  1362. tv_std = TV_STD_PAL_60;
  1363. DRM_INFO("Default TV standard: PAL-60\n");
  1364. break;
  1365. case ATOM_TV_SECAM:
  1366. tv_std = TV_STD_SECAM;
  1367. DRM_INFO("Default TV standard: SECAM\n");
  1368. break;
  1369. default:
  1370. tv_std = TV_STD_NTSC;
  1371. DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
  1372. break;
  1373. }
  1374. }
  1375. return tv_std;
  1376. }
  1377. struct radeon_encoder_tv_dac *
  1378. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1379. {
  1380. struct drm_device *dev = encoder->base.dev;
  1381. struct radeon_device *rdev = dev->dev_private;
  1382. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1383. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1384. uint16_t data_offset;
  1385. struct _COMPASSIONATE_DATA *dac_info;
  1386. uint8_t frev, crev;
  1387. uint8_t bg, dac;
  1388. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1389. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1390. &frev, &crev, &data_offset)) {
  1391. dac_info = (struct _COMPASSIONATE_DATA *)
  1392. (mode_info->atom_context->bios + data_offset);
  1393. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1394. if (!tv_dac)
  1395. return NULL;
  1396. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1397. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1398. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1399. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1400. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1401. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1402. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1403. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1404. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1405. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1406. }
  1407. return tv_dac;
  1408. }
  1409. static const char *thermal_controller_names[] = {
  1410. "NONE",
  1411. "lm63",
  1412. "adm1032",
  1413. "adm1030",
  1414. "max6649",
  1415. "lm64",
  1416. "f75375",
  1417. "asc7xxx",
  1418. };
  1419. static const char *pp_lib_thermal_controller_names[] = {
  1420. "NONE",
  1421. "lm63",
  1422. "adm1032",
  1423. "adm1030",
  1424. "max6649",
  1425. "lm64",
  1426. "f75375",
  1427. "RV6xx",
  1428. "RV770",
  1429. "adt7473",
  1430. "External GPIO",
  1431. "Evergreen",
  1432. "adt7473 with internal",
  1433. };
  1434. union power_info {
  1435. struct _ATOM_POWERPLAY_INFO info;
  1436. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1437. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1438. struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
  1439. };
  1440. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  1441. {
  1442. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1443. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1444. u16 data_offset;
  1445. u8 frev, crev;
  1446. u32 misc, misc2 = 0, sclk, mclk;
  1447. union power_info *power_info;
  1448. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1449. struct _ATOM_PPLIB_STATE *power_state;
  1450. int num_modes = 0, i, j;
  1451. int state_index = 0, mode_index = 0;
  1452. struct radeon_i2c_bus_rec i2c_bus;
  1453. rdev->pm.default_power_state_index = -1;
  1454. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1455. &frev, &crev, &data_offset)) {
  1456. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1457. if (frev < 4) {
  1458. /* add the i2c bus for thermal/fan chip */
  1459. if (power_info->info.ucOverdriveThermalController > 0) {
  1460. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1461. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1462. power_info->info.ucOverdriveControllerAddress >> 1);
  1463. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1464. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1465. if (rdev->pm.i2c_bus) {
  1466. struct i2c_board_info info = { };
  1467. const char *name = thermal_controller_names[power_info->info.
  1468. ucOverdriveThermalController];
  1469. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1470. strlcpy(info.type, name, sizeof(info.type));
  1471. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1472. }
  1473. }
  1474. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1475. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1476. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1477. /* last mode is usually default, array is low to high */
  1478. for (i = 0; i < num_modes; i++) {
  1479. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1480. switch (frev) {
  1481. case 1:
  1482. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1483. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1484. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1485. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1486. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1487. /* skip invalid modes */
  1488. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1489. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1490. continue;
  1491. rdev->pm.power_state[state_index].pcie_lanes =
  1492. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1493. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1494. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1495. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1496. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1497. VOLTAGE_GPIO;
  1498. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1499. radeon_lookup_gpio(rdev,
  1500. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1501. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1502. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1503. true;
  1504. else
  1505. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1506. false;
  1507. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1508. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1509. VOLTAGE_VDDC;
  1510. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1511. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1512. }
  1513. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1514. rdev->pm.power_state[state_index].misc = misc;
  1515. /* order matters! */
  1516. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1517. rdev->pm.power_state[state_index].type =
  1518. POWER_STATE_TYPE_POWERSAVE;
  1519. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1520. rdev->pm.power_state[state_index].type =
  1521. POWER_STATE_TYPE_BATTERY;
  1522. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1523. rdev->pm.power_state[state_index].type =
  1524. POWER_STATE_TYPE_BATTERY;
  1525. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1526. rdev->pm.power_state[state_index].type =
  1527. POWER_STATE_TYPE_BALANCED;
  1528. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1529. rdev->pm.power_state[state_index].type =
  1530. POWER_STATE_TYPE_PERFORMANCE;
  1531. rdev->pm.power_state[state_index].flags &=
  1532. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1533. }
  1534. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1535. rdev->pm.power_state[state_index].type =
  1536. POWER_STATE_TYPE_DEFAULT;
  1537. rdev->pm.default_power_state_index = state_index;
  1538. rdev->pm.power_state[state_index].default_clock_mode =
  1539. &rdev->pm.power_state[state_index].clock_info[0];
  1540. rdev->pm.power_state[state_index].flags &=
  1541. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1542. } else if (state_index == 0) {
  1543. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1544. RADEON_PM_MODE_NO_DISPLAY;
  1545. }
  1546. state_index++;
  1547. break;
  1548. case 2:
  1549. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1550. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1551. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1552. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1553. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1554. /* skip invalid modes */
  1555. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1556. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1557. continue;
  1558. rdev->pm.power_state[state_index].pcie_lanes =
  1559. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1560. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1561. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1562. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1563. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1564. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1565. VOLTAGE_GPIO;
  1566. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1567. radeon_lookup_gpio(rdev,
  1568. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1569. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1570. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1571. true;
  1572. else
  1573. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1574. false;
  1575. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1576. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1577. VOLTAGE_VDDC;
  1578. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1579. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1580. }
  1581. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1582. rdev->pm.power_state[state_index].misc = misc;
  1583. rdev->pm.power_state[state_index].misc2 = misc2;
  1584. /* order matters! */
  1585. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1586. rdev->pm.power_state[state_index].type =
  1587. POWER_STATE_TYPE_POWERSAVE;
  1588. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1589. rdev->pm.power_state[state_index].type =
  1590. POWER_STATE_TYPE_BATTERY;
  1591. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1592. rdev->pm.power_state[state_index].type =
  1593. POWER_STATE_TYPE_BATTERY;
  1594. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1595. rdev->pm.power_state[state_index].type =
  1596. POWER_STATE_TYPE_BALANCED;
  1597. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1598. rdev->pm.power_state[state_index].type =
  1599. POWER_STATE_TYPE_PERFORMANCE;
  1600. rdev->pm.power_state[state_index].flags &=
  1601. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1602. }
  1603. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1604. rdev->pm.power_state[state_index].type =
  1605. POWER_STATE_TYPE_BALANCED;
  1606. if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
  1607. rdev->pm.power_state[state_index].flags &=
  1608. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1609. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1610. rdev->pm.power_state[state_index].type =
  1611. POWER_STATE_TYPE_DEFAULT;
  1612. rdev->pm.default_power_state_index = state_index;
  1613. rdev->pm.power_state[state_index].default_clock_mode =
  1614. &rdev->pm.power_state[state_index].clock_info[0];
  1615. rdev->pm.power_state[state_index].flags &=
  1616. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1617. } else if (state_index == 0) {
  1618. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1619. RADEON_PM_MODE_NO_DISPLAY;
  1620. }
  1621. state_index++;
  1622. break;
  1623. case 3:
  1624. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1625. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1626. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1627. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1628. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1629. /* skip invalid modes */
  1630. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1631. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1632. continue;
  1633. rdev->pm.power_state[state_index].pcie_lanes =
  1634. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1635. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1636. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1637. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1638. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1639. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1640. VOLTAGE_GPIO;
  1641. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1642. radeon_lookup_gpio(rdev,
  1643. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1644. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1645. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1646. true;
  1647. else
  1648. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1649. false;
  1650. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1651. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1652. VOLTAGE_VDDC;
  1653. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1654. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1655. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1656. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1657. true;
  1658. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1659. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1660. }
  1661. }
  1662. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1663. rdev->pm.power_state[state_index].misc = misc;
  1664. rdev->pm.power_state[state_index].misc2 = misc2;
  1665. /* order matters! */
  1666. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1667. rdev->pm.power_state[state_index].type =
  1668. POWER_STATE_TYPE_POWERSAVE;
  1669. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1670. rdev->pm.power_state[state_index].type =
  1671. POWER_STATE_TYPE_BATTERY;
  1672. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1673. rdev->pm.power_state[state_index].type =
  1674. POWER_STATE_TYPE_BATTERY;
  1675. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1676. rdev->pm.power_state[state_index].type =
  1677. POWER_STATE_TYPE_BALANCED;
  1678. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1679. rdev->pm.power_state[state_index].type =
  1680. POWER_STATE_TYPE_PERFORMANCE;
  1681. rdev->pm.power_state[state_index].flags &=
  1682. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1683. }
  1684. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1685. rdev->pm.power_state[state_index].type =
  1686. POWER_STATE_TYPE_BALANCED;
  1687. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1688. rdev->pm.power_state[state_index].type =
  1689. POWER_STATE_TYPE_DEFAULT;
  1690. rdev->pm.default_power_state_index = state_index;
  1691. rdev->pm.power_state[state_index].default_clock_mode =
  1692. &rdev->pm.power_state[state_index].clock_info[0];
  1693. } else if (state_index == 0) {
  1694. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1695. RADEON_PM_MODE_NO_DISPLAY;
  1696. }
  1697. state_index++;
  1698. break;
  1699. }
  1700. }
  1701. /* last mode is usually default */
  1702. if (rdev->pm.default_power_state_index == -1) {
  1703. rdev->pm.power_state[state_index - 1].type =
  1704. POWER_STATE_TYPE_DEFAULT;
  1705. rdev->pm.default_power_state_index = state_index - 1;
  1706. rdev->pm.power_state[state_index - 1].default_clock_mode =
  1707. &rdev->pm.power_state[state_index - 1].clock_info[0];
  1708. rdev->pm.power_state[state_index].flags &=
  1709. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1710. rdev->pm.power_state[state_index].misc = 0;
  1711. rdev->pm.power_state[state_index].misc2 = 0;
  1712. }
  1713. } else {
  1714. int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  1715. uint8_t fw_frev, fw_crev;
  1716. uint16_t fw_data_offset, vddc = 0;
  1717. union firmware_info *firmware_info;
  1718. ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
  1719. if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
  1720. &fw_frev, &fw_crev, &fw_data_offset)) {
  1721. firmware_info =
  1722. (union firmware_info *)(mode_info->atom_context->bios +
  1723. fw_data_offset);
  1724. vddc = firmware_info->info_14.usBootUpVDDCVoltage;
  1725. }
  1726. /* add the i2c bus for thermal/fan chip */
  1727. if (controller->ucType > 0) {
  1728. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  1729. DRM_INFO("Internal thermal controller %s fan control\n",
  1730. (controller->ucFanParameters &
  1731. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1732. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  1733. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  1734. DRM_INFO("Internal thermal controller %s fan control\n",
  1735. (controller->ucFanParameters &
  1736. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1737. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  1738. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  1739. DRM_INFO("Internal thermal controller %s fan control\n",
  1740. (controller->ucFanParameters &
  1741. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1742. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  1743. } else if ((controller->ucType ==
  1744. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
  1745. (controller->ucType ==
  1746. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
  1747. DRM_INFO("Special thermal controller config\n");
  1748. } else {
  1749. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  1750. pp_lib_thermal_controller_names[controller->ucType],
  1751. controller->ucI2cAddress >> 1,
  1752. (controller->ucFanParameters &
  1753. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  1754. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  1755. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1756. if (rdev->pm.i2c_bus) {
  1757. struct i2c_board_info info = { };
  1758. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  1759. info.addr = controller->ucI2cAddress >> 1;
  1760. strlcpy(info.type, name, sizeof(info.type));
  1761. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1762. }
  1763. }
  1764. }
  1765. /* first mode is usually default, followed by low to high */
  1766. for (i = 0; i < power_info->info_4.ucNumStates; i++) {
  1767. mode_index = 0;
  1768. power_state = (struct _ATOM_PPLIB_STATE *)
  1769. (mode_info->atom_context->bios +
  1770. data_offset +
  1771. le16_to_cpu(power_info->info_4.usStateArrayOffset) +
  1772. i * power_info->info_4.ucStateEntrySize);
  1773. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1774. (mode_info->atom_context->bios +
  1775. data_offset +
  1776. le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
  1777. (power_state->ucNonClockStateIndex *
  1778. power_info->info_4.ucNonClockSize));
  1779. for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
  1780. if (rdev->flags & RADEON_IS_IGP) {
  1781. struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
  1782. (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
  1783. (mode_info->atom_context->bios +
  1784. data_offset +
  1785. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1786. (power_state->ucClockStateIndices[j] *
  1787. power_info->info_4.ucClockInfoSize));
  1788. sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
  1789. sclk |= clock_info->ucLowEngineClockHigh << 16;
  1790. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1791. /* skip invalid modes */
  1792. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  1793. continue;
  1794. /* voltage works differently on IGPs */
  1795. mode_index++;
  1796. } else if (ASIC_IS_DCE4(rdev)) {
  1797. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
  1798. (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
  1799. (mode_info->atom_context->bios +
  1800. data_offset +
  1801. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1802. (power_state->ucClockStateIndices[j] *
  1803. power_info->info_4.ucClockInfoSize));
  1804. sclk = le16_to_cpu(clock_info->usEngineClockLow);
  1805. sclk |= clock_info->ucEngineClockHigh << 16;
  1806. mclk = le16_to_cpu(clock_info->usMemoryClockLow);
  1807. mclk |= clock_info->ucMemoryClockHigh << 16;
  1808. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1809. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1810. /* skip invalid modes */
  1811. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  1812. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  1813. continue;
  1814. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1815. VOLTAGE_SW;
  1816. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1817. clock_info->usVDDC;
  1818. /* XXX usVDDCI */
  1819. mode_index++;
  1820. } else {
  1821. struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
  1822. (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
  1823. (mode_info->atom_context->bios +
  1824. data_offset +
  1825. le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
  1826. (power_state->ucClockStateIndices[j] *
  1827. power_info->info_4.ucClockInfoSize));
  1828. sclk = le16_to_cpu(clock_info->usEngineClockLow);
  1829. sclk |= clock_info->ucEngineClockHigh << 16;
  1830. mclk = le16_to_cpu(clock_info->usMemoryClockLow);
  1831. mclk |= clock_info->ucMemoryClockHigh << 16;
  1832. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  1833. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  1834. /* skip invalid modes */
  1835. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  1836. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  1837. continue;
  1838. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  1839. VOLTAGE_SW;
  1840. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  1841. clock_info->usVDDC;
  1842. mode_index++;
  1843. }
  1844. }
  1845. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  1846. if (mode_index) {
  1847. misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1848. misc2 = le16_to_cpu(non_clock_info->usClassification);
  1849. rdev->pm.power_state[state_index].misc = misc;
  1850. rdev->pm.power_state[state_index].misc2 = misc2;
  1851. rdev->pm.power_state[state_index].pcie_lanes =
  1852. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  1853. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  1854. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  1855. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  1856. rdev->pm.power_state[state_index].type =
  1857. POWER_STATE_TYPE_BATTERY;
  1858. break;
  1859. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  1860. rdev->pm.power_state[state_index].type =
  1861. POWER_STATE_TYPE_BALANCED;
  1862. break;
  1863. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  1864. rdev->pm.power_state[state_index].type =
  1865. POWER_STATE_TYPE_PERFORMANCE;
  1866. break;
  1867. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  1868. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  1869. rdev->pm.power_state[state_index].type =
  1870. POWER_STATE_TYPE_PERFORMANCE;
  1871. break;
  1872. }
  1873. rdev->pm.power_state[state_index].flags = 0;
  1874. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  1875. rdev->pm.power_state[state_index].flags |=
  1876. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1877. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1878. rdev->pm.power_state[state_index].type =
  1879. POWER_STATE_TYPE_DEFAULT;
  1880. rdev->pm.default_power_state_index = state_index;
  1881. rdev->pm.power_state[state_index].default_clock_mode =
  1882. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  1883. /* patch the table values with the default slck/mclk from firmware info */
  1884. for (j = 0; j < mode_index; j++) {
  1885. rdev->pm.power_state[state_index].clock_info[j].mclk =
  1886. rdev->clock.default_mclk;
  1887. rdev->pm.power_state[state_index].clock_info[j].sclk =
  1888. rdev->clock.default_sclk;
  1889. if (vddc)
  1890. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  1891. vddc;
  1892. }
  1893. }
  1894. state_index++;
  1895. }
  1896. }
  1897. /* if multiple clock modes, mark the lowest as no display */
  1898. for (i = 0; i < state_index; i++) {
  1899. if (rdev->pm.power_state[i].num_clock_modes > 1)
  1900. rdev->pm.power_state[i].clock_info[0].flags |=
  1901. RADEON_PM_MODE_NO_DISPLAY;
  1902. }
  1903. /* first mode is usually default */
  1904. if (rdev->pm.default_power_state_index == -1) {
  1905. rdev->pm.power_state[0].type =
  1906. POWER_STATE_TYPE_DEFAULT;
  1907. rdev->pm.default_power_state_index = 0;
  1908. rdev->pm.power_state[0].default_clock_mode =
  1909. &rdev->pm.power_state[0].clock_info[0];
  1910. }
  1911. }
  1912. } else {
  1913. /* add the default mode */
  1914. rdev->pm.power_state[state_index].type =
  1915. POWER_STATE_TYPE_DEFAULT;
  1916. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1917. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  1918. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  1919. rdev->pm.power_state[state_index].default_clock_mode =
  1920. &rdev->pm.power_state[state_index].clock_info[0];
  1921. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1922. rdev->pm.power_state[state_index].pcie_lanes = 16;
  1923. rdev->pm.default_power_state_index = state_index;
  1924. rdev->pm.power_state[state_index].flags = 0;
  1925. state_index++;
  1926. }
  1927. rdev->pm.num_power_states = state_index;
  1928. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  1929. rdev->pm.current_clock_mode_index = 0;
  1930. rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  1931. }
  1932. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  1933. {
  1934. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  1935. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  1936. args.ucEnable = enable;
  1937. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1938. }
  1939. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  1940. {
  1941. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  1942. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  1943. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1944. return args.ulReturnEngineClock;
  1945. }
  1946. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  1947. {
  1948. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  1949. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  1950. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1951. return args.ulReturnMemoryClock;
  1952. }
  1953. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  1954. uint32_t eng_clock)
  1955. {
  1956. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  1957. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  1958. args.ulTargetEngineClock = eng_clock; /* 10 khz */
  1959. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1960. }
  1961. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  1962. uint32_t mem_clock)
  1963. {
  1964. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  1965. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  1966. if (rdev->flags & RADEON_IS_IGP)
  1967. return;
  1968. args.ulTargetMemoryClock = mem_clock; /* 10 khz */
  1969. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1970. }
  1971. union set_voltage {
  1972. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  1973. struct _SET_VOLTAGE_PARAMETERS v1;
  1974. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  1975. };
  1976. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
  1977. {
  1978. union set_voltage args;
  1979. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  1980. u8 frev, crev, volt_index = level;
  1981. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  1982. return;
  1983. switch (crev) {
  1984. case 1:
  1985. args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  1986. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  1987. args.v1.ucVoltageIndex = volt_index;
  1988. break;
  1989. case 2:
  1990. args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
  1991. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  1992. args.v2.usVoltageLevel = cpu_to_le16(level);
  1993. break;
  1994. default:
  1995. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  1996. return;
  1997. }
  1998. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  1999. }
  2000. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  2001. {
  2002. struct radeon_device *rdev = dev->dev_private;
  2003. uint32_t bios_2_scratch, bios_6_scratch;
  2004. if (rdev->family >= CHIP_R600) {
  2005. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2006. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2007. } else {
  2008. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2009. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2010. }
  2011. /* let the bios control the backlight */
  2012. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  2013. /* tell the bios not to handle mode switching */
  2014. bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
  2015. if (rdev->family >= CHIP_R600) {
  2016. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2017. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2018. } else {
  2019. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2020. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2021. }
  2022. }
  2023. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  2024. {
  2025. uint32_t scratch_reg;
  2026. int i;
  2027. if (rdev->family >= CHIP_R600)
  2028. scratch_reg = R600_BIOS_0_SCRATCH;
  2029. else
  2030. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2031. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2032. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  2033. }
  2034. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  2035. {
  2036. uint32_t scratch_reg;
  2037. int i;
  2038. if (rdev->family >= CHIP_R600)
  2039. scratch_reg = R600_BIOS_0_SCRATCH;
  2040. else
  2041. scratch_reg = RADEON_BIOS_0_SCRATCH;
  2042. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  2043. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  2044. }
  2045. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  2046. {
  2047. struct drm_device *dev = encoder->dev;
  2048. struct radeon_device *rdev = dev->dev_private;
  2049. uint32_t bios_6_scratch;
  2050. if (rdev->family >= CHIP_R600)
  2051. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2052. else
  2053. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2054. if (lock)
  2055. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  2056. else
  2057. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  2058. if (rdev->family >= CHIP_R600)
  2059. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2060. else
  2061. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2062. }
  2063. /* at some point we may want to break this out into individual functions */
  2064. void
  2065. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  2066. struct drm_encoder *encoder,
  2067. bool connected)
  2068. {
  2069. struct drm_device *dev = connector->dev;
  2070. struct radeon_device *rdev = dev->dev_private;
  2071. struct radeon_connector *radeon_connector =
  2072. to_radeon_connector(connector);
  2073. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2074. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  2075. if (rdev->family >= CHIP_R600) {
  2076. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  2077. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2078. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  2079. } else {
  2080. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  2081. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2082. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  2083. }
  2084. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  2085. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  2086. if (connected) {
  2087. DRM_DEBUG_KMS("TV1 connected\n");
  2088. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  2089. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  2090. } else {
  2091. DRM_DEBUG_KMS("TV1 disconnected\n");
  2092. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  2093. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  2094. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  2095. }
  2096. }
  2097. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  2098. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  2099. if (connected) {
  2100. DRM_DEBUG_KMS("CV connected\n");
  2101. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  2102. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  2103. } else {
  2104. DRM_DEBUG_KMS("CV disconnected\n");
  2105. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  2106. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  2107. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  2108. }
  2109. }
  2110. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  2111. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  2112. if (connected) {
  2113. DRM_DEBUG_KMS("LCD1 connected\n");
  2114. bios_0_scratch |= ATOM_S0_LCD1;
  2115. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  2116. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  2117. } else {
  2118. DRM_DEBUG_KMS("LCD1 disconnected\n");
  2119. bios_0_scratch &= ~ATOM_S0_LCD1;
  2120. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  2121. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  2122. }
  2123. }
  2124. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  2125. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  2126. if (connected) {
  2127. DRM_DEBUG_KMS("CRT1 connected\n");
  2128. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  2129. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  2130. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  2131. } else {
  2132. DRM_DEBUG_KMS("CRT1 disconnected\n");
  2133. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  2134. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  2135. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  2136. }
  2137. }
  2138. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  2139. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  2140. if (connected) {
  2141. DRM_DEBUG_KMS("CRT2 connected\n");
  2142. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  2143. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  2144. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  2145. } else {
  2146. DRM_DEBUG_KMS("CRT2 disconnected\n");
  2147. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  2148. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  2149. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  2150. }
  2151. }
  2152. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  2153. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  2154. if (connected) {
  2155. DRM_DEBUG_KMS("DFP1 connected\n");
  2156. bios_0_scratch |= ATOM_S0_DFP1;
  2157. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  2158. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  2159. } else {
  2160. DRM_DEBUG_KMS("DFP1 disconnected\n");
  2161. bios_0_scratch &= ~ATOM_S0_DFP1;
  2162. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  2163. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  2164. }
  2165. }
  2166. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  2167. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  2168. if (connected) {
  2169. DRM_DEBUG_KMS("DFP2 connected\n");
  2170. bios_0_scratch |= ATOM_S0_DFP2;
  2171. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  2172. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  2173. } else {
  2174. DRM_DEBUG_KMS("DFP2 disconnected\n");
  2175. bios_0_scratch &= ~ATOM_S0_DFP2;
  2176. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  2177. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  2178. }
  2179. }
  2180. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  2181. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  2182. if (connected) {
  2183. DRM_DEBUG_KMS("DFP3 connected\n");
  2184. bios_0_scratch |= ATOM_S0_DFP3;
  2185. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  2186. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  2187. } else {
  2188. DRM_DEBUG_KMS("DFP3 disconnected\n");
  2189. bios_0_scratch &= ~ATOM_S0_DFP3;
  2190. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  2191. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  2192. }
  2193. }
  2194. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  2195. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  2196. if (connected) {
  2197. DRM_DEBUG_KMS("DFP4 connected\n");
  2198. bios_0_scratch |= ATOM_S0_DFP4;
  2199. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  2200. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  2201. } else {
  2202. DRM_DEBUG_KMS("DFP4 disconnected\n");
  2203. bios_0_scratch &= ~ATOM_S0_DFP4;
  2204. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  2205. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  2206. }
  2207. }
  2208. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  2209. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  2210. if (connected) {
  2211. DRM_DEBUG_KMS("DFP5 connected\n");
  2212. bios_0_scratch |= ATOM_S0_DFP5;
  2213. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  2214. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  2215. } else {
  2216. DRM_DEBUG_KMS("DFP5 disconnected\n");
  2217. bios_0_scratch &= ~ATOM_S0_DFP5;
  2218. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  2219. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  2220. }
  2221. }
  2222. if (rdev->family >= CHIP_R600) {
  2223. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  2224. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2225. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  2226. } else {
  2227. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  2228. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2229. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  2230. }
  2231. }
  2232. void
  2233. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  2234. {
  2235. struct drm_device *dev = encoder->dev;
  2236. struct radeon_device *rdev = dev->dev_private;
  2237. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2238. uint32_t bios_3_scratch;
  2239. if (rdev->family >= CHIP_R600)
  2240. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  2241. else
  2242. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  2243. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2244. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  2245. bios_3_scratch |= (crtc << 18);
  2246. }
  2247. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2248. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  2249. bios_3_scratch |= (crtc << 24);
  2250. }
  2251. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2252. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  2253. bios_3_scratch |= (crtc << 16);
  2254. }
  2255. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2256. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  2257. bios_3_scratch |= (crtc << 20);
  2258. }
  2259. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2260. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  2261. bios_3_scratch |= (crtc << 17);
  2262. }
  2263. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2264. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  2265. bios_3_scratch |= (crtc << 19);
  2266. }
  2267. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2268. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  2269. bios_3_scratch |= (crtc << 23);
  2270. }
  2271. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2272. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  2273. bios_3_scratch |= (crtc << 25);
  2274. }
  2275. if (rdev->family >= CHIP_R600)
  2276. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  2277. else
  2278. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  2279. }
  2280. void
  2281. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  2282. {
  2283. struct drm_device *dev = encoder->dev;
  2284. struct radeon_device *rdev = dev->dev_private;
  2285. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  2286. uint32_t bios_2_scratch;
  2287. if (rdev->family >= CHIP_R600)
  2288. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  2289. else
  2290. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  2291. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  2292. if (on)
  2293. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  2294. else
  2295. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  2296. }
  2297. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  2298. if (on)
  2299. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  2300. else
  2301. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  2302. }
  2303. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  2304. if (on)
  2305. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  2306. else
  2307. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  2308. }
  2309. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  2310. if (on)
  2311. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  2312. else
  2313. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  2314. }
  2315. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  2316. if (on)
  2317. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  2318. else
  2319. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  2320. }
  2321. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  2322. if (on)
  2323. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  2324. else
  2325. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  2326. }
  2327. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  2328. if (on)
  2329. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  2330. else
  2331. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  2332. }
  2333. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  2334. if (on)
  2335. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  2336. else
  2337. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  2338. }
  2339. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  2340. if (on)
  2341. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  2342. else
  2343. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  2344. }
  2345. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  2346. if (on)
  2347. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  2348. else
  2349. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  2350. }
  2351. if (rdev->family >= CHIP_R600)
  2352. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  2353. else
  2354. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  2355. }