radeon_atombios.c 86 KB

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